PHP prepared statement doesn't work with intval()
<p>Please look my code:</p>

<pre class="lang-php prettyprint-override"><code>$insertStmt = $conn-&gt;prepare("INSERT INTO orders (OrderID, OrderTrackingNumber, OrderTotal, CustomerID) VALUES (?, ?, ?, ?)");
$insertStmt-&gt;bind_param("ssdi", $orderID, strval("Not Ship Yet"), $orderTotal, $userID);
if ($insertStmt-&gt;execute()) {
    $insertStmt = $conn-&gt;prepare("INSERT INTO ordersproducts (OrderID, ProductID, ProductSold) VALUES (?, ?, ?)");
    $updateStmt = $conn-&gt;prepare("UPDATE products SET ProductQuantity = ? WHERE ProductID = ?");
    foreach ($orderedProducts as $orderedProduct) {
        $productQuantity = intval($orderedProduct-&gt;ProductQuantity) - intval($orderedProduct-&gt;ProductAddedQuantity);
        $insertStmt-&gt;bind_param("sii", $orderID, intval($orderedProduct-&gt;ProductID), intval($orderedProduct-&gt;ProductAddedQuantity));
        $updateStmt-&gt;bind_param("ii", intval($productQuantity), settype($orderedProduct-&gt;ProductID, "integer"));
        if ($insertStmt-&gt;execute() &amp;&amp; $updateStmt-&gt;execute()) {
            if ($updateStmt-&gt;affected_rows == 1) {
                $isSuccefull = TRUE;
            } else {
                $isSuccefull = FALSE;
                break;
            }

        } else {
            $isSuccefull = FALSE;
            echo $insertStmt-&gt;error . " | " . $updateStmt-&gt;error;
            break;
        }
    }
}
</code></pre>

<p>At the line of <code>$updateStmt-&gt;bind_param</code>, if I convert <code>$orderedProduct-&gt;ProductID</code> to int by <code>intval($orderedProduct-&gt;ProductID)</code>, the <code>updateStmt</code> will not work <code>($updateStmt-&gt;affected_rows = 0)</code>. However, I use <code>settype($orderedProduct-&gt;ProductID, "integer");</code> then it will work like a champ. And only this place gets that issue; others work very well.</p>

<p>Why?</p>

<p>Thanks for helping me.</p>