且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

多个MYSQLi预备语句

更新时间:2022-06-14 23:40:36

您的代码不错,但是您不应使用相同的名称$stmt

your code is good however you should dont name them the same name $stmt

第一个陈述是$stmt

然后给第二个陈述另外一个名称,例如$stmt2.或您喜欢的名字.

then give second statment other name like $stmt2. or what ever name you like.

示例:

$stmt = $con->prepare("INSERT INTO reviews (order_id, comment) VALUES (?, ?)");
$stmt->bind_param('is', $order_id, $comment);
$stmt->execute(); 
$stmt->close();


// Update transactions to show review added
$stmt2 = $con->prepare("UPDATE transactions SET review = ? WHERE order_id = ?");
$stmt2->bind_param('ii', 1, $order_id);
$stmt2->execute(); 
$stmt2->close(); 

并调试您的代码,看看错误在哪里使用

and to debug your code and see where is the error use this.

if ($stmt = $con->prepare("INSERT INTO reviews (order_id, comment) VALUES (?, ?)") ){
   $stmt->bind_param('is', $order_id, $comment);
   $stmt->execute(); 
   $stmt->close();
    }
 else {printf("Error message:: %s\n", $con->error);}