简体   繁体   English

在查询中使用特定数字时,mysqli_stmt_execute 不会更新随机行?

[英]mysqli_stmt_execute doesn't update random rows when using specific number in query?

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.例如:如果我将价格更改为 67.48 - 相关行将完美更新。

However if I use the price 67.49 then the rows are not updated?但是,如果我使用 67.49 的价格,那么行不会更新?

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 ).您在数据库中插入双值(价格),但您告诉 PHP 将该值视为 integer (使用i )。
You need to use d for double.您需要将d用于双精度。

Your code to bind the params will be:您绑定参数的代码将是:

// Bind the variables:
mysqli_stmt_bind_param($stmt1, 'di', $price, $id);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM