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

问题描述 投票:0回答:1

这是最奇怪的事情--我有一个动态生成的表单,当处理时,更新数据库中的价格表。除了当我使用一个特定的价格时,所有的工作似乎都是正确的?

而且这只发生在随机的行上。

例如:如果我把价格改为67.48,问题行就会被完美更新。

然而,如果我使用的价格67.49,那么行不更新?

我完全不明白了。这是我的更新代码。

// 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.
php database mysqli
1个回答
-1
投票

你在数据库中插入了双值(价格),但你告诉PHP将该值作为整数处理(使用了 i). 您需要使用 d 为双。

绑定params的代码是:

// Bind the variables:
mysqli_stmt_bind_param($stmt1, 'di', $price, $id);
© www.soinside.com 2019 - 2024. All rights reserved.