Hi I have a table generated from php, it is editable, I want to save edited values to database. I have no Idea how can I do this as there are many rows(dynamic) on a page. Here
Let me give you with the best way First your database tables have spaces: correct that e.g.
from $row["Initial Stock"]
to $row["Initial_Stock"]
Then i will propose you use ajax instead of wasting time clicking buttons
The HTML Page
Sl Number
Product Id
Product Name
Product Catagory
Retal Price
Max Price
Min Price
Initial Stock
Quantity Sold
Current Stock
Last Order
Edit/Update
">
">
">
">
">
">
">
">
">
">
">
";
fetch_assoc()) ?>
And the update php page
false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
?>
$val)
{
//clean post values
$field_id = strip_tags(trim($field_name));
//from the fieldname:user_id we need to get user_id
$split_data = explode(':', $field_id);
$product_id = $split_data[1];
$field_name = $split_data[0];
if(!empty($product_id) && !empty($field_name) && !empty($val))
{
$affected_rows = $db->exec("UPDATE yourtable SET $field_name = '$val' WHERE product_ID = $product_id");
echo $affected_rows;
echo "Updated";
} else {
echo "Invalid Requests";
}
}
}
else {
echo "Invalid Requests";
}
?>