This is the strangest thing - I have dynamically generated form that, when processed, updates a database table with prices. All seems to work correctly except when I use a specific price?
And this only happens to random rows:
Eg: If I change the price to 67.48 - the rows in question are updated perfectly.
However if I use the price 67.49 then the rows are not updated?
I'm completely stumped. Here is my update code.
// Define the queries:
$q1 = 'UPDATE variations SET retail_price= ? WHERE id=?';
// Prepare the statements:
$stmt1 = mysqli_prepare($dbc, $q1);
// Bind the variables:
mysqli_stmt_bind_param($stmt1, 'ii', $price, $id);
// Count the number of affected rows:
$affected = 0;
// Loop through each submitted value:
foreach ($_POST['add'] as $sku => $price) {
//parse the price remove decimals
$price = $price*100;
// Validate the added quantity:
if (filter_var($price, FILTER_VALIDATE_INT, array('min_range' => 1))) {
// Parse the SKU:
$id = parse_sku($sku);
// Execute the query:
mysqli_stmt_execute($stmt1);
// Add to the affected rows:
$affected += mysqli_stmt_affected_rows($stmt1);
} // End of IF.
} // End of FOREACH.
You are insterted double value in the database (for the price), but you are telling to PHP to treat the value as integer (using the i
).
You need to use d
for double.
Your code to bind the params will be:
// Bind the variables:
mysqli_stmt_bind_param($stmt1, 'di', $price, $id);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.