bind_param() 的-6ren">
gpt4 book ai didi

php - 准备好的语句错误 "No data supplied for parameters in prepared statement"

转载 作者:行者123 更新时间:2023-11-29 03:07:08 29 4
gpt4 key购买 nike

我正在尝试使用事务更新 2 个不同的表。对于我的第一个查询,我收到错误“没有为准备好的语句中的参数提供数据”。我的第二个查询进行得很好。我知道错误是指传递给 $stmt->bind_param() 的变量。我已经检查,三重检查并且可以确认我传递给它的所有变量实际上都包含值。我还检查以确保传递的值由“s”或“i”正确指示。我的问题是我是否有语法错误会给我这条错误消息,或者是否有关于如何修复它的任何其他建议?

function updateClient($id,$first,$last,$email,$phone,$phoneCarrier,$tz,$wdh1,$wdh2,$weh1,$weh2,$goals){
global $conguest;
global $database;

$conguest->autocommit(false);

//update the client tabel
$sql="UPDATE $database.client SET clientFirst = '?', clientLast = '?', clientEmail ='?', clientPhone =?, phoneCarrierId =?, timezoneId =?, clientHour1 ='?',clientHour2 ='?',clientHour3 ='?',clientHour4 ='?'
WHERE clientId = ?";

if($stmt = $conguest->prepare($sql)){
$stmt->bind_param('ssssiissssi', $first, $last, $email, $phone, $phoneCarrier, $tz, $wdh1, $wdh2, $weh1, $weh2, $id);
$stmt->execute();
$clientupdate = $stmt->affected_rows;
$stmt->close();
}
//update the goals table
$sql = "UPDATE $database.goal SET goalContent=?, categoryId = ?, goalDate=now() WHERE goalId = ?";

foreach ($goals as $goal) {
if ($stmt = $conguest->prepare($sql)) {
$stmt->bind_param('sii', $goal['goal'],$goal['cat'], $goal['id']);
$stmt->execute();
$i = $stmt->affected_rows;
$stmt->close();
}
if($i){
$goalupdate ++;
}
}
//test that all updates worked
echo "$clientupdate, $goalupdate";
exit;
if($clientupdate ==1 && $goalupdate == 3){
$conguest->commit();
$conguest->autocommit(true);
return 1;
}else{
$conguest->rollback();
$conguest->autocommit(true);
return 0;
}

最佳答案

删除占位符周围的单引号。替换

$sql="UPDATE $database.client SET clientFirst = '?', clientLast = '?', clientEmail ='?', clientPhone =?, phoneCarrierId =?, timezoneId =?, clientHour1 ='?',clientHour2 ='?',clientHour3 ='?',clientHour4 ='?' WHERE clientId = ?";

$sql="UPDATE $database.client SET clientFirst = ?, clientLast = ?, clientEmail = ?, clientPhone = ?, phoneCarrierId = ?, timezoneId = ?, clientHour1 = ?, clientHour2 = ?,clientHour3 = ?,clientHour4 = ? WHERE clientId = ?";

此外,在“where clientid”之前有一个换行符。我不知道这是否相关。

关于php - 准备好的语句错误 "No data supplied for parameters in prepared statement",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13546379/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com