gpt4 book ai didi

php - 当我在那里使用 if else 时出现 mysql 错误

转载 作者:行者123 更新时间:2023-11-29 11:35:46 26 4
gpt4 key购买 nike

当我在那里使用 if else 时,出现 mysql 错误。我不知道我应该做什么,当我使用重复条件进行更新时,它不起作用,我无法找到错误在哪里

this is the error which is i am getting.

ERROR:SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt=$conn->prepare("SELECT uniqueid FROM hotelcarttemp WHERE uniqueid=:uniqueid");
$stmt->execute(array(':uniqueid'=>$uniqueid));
$count=$stmt1->rowCount();
echo "count-".$count;
if($count>0)
{
$sql = "UPDATE hotelcarttemp SET `hotelname`='".$hotelname."',`roomtype`='".$roomtype."',`checkin`='".$checkin."',`checkout`='".$checkout."',`Country`='".$Country."',`Destination`='".$Destination."',`price`='".$price."' WHERE uniqueid='".$uniqueid."'";
echo "sql- ".print_r($sql);
$stmt = $conn->prepare($sql);
// echo print_r($stmt);
$stmt->execute();
}
else
{
$sql = "INSERT INTO hotelcarttemp (timestamp, packageid, uniqueid, hotelname, roomtype, checkin, checkout, Country, Destination, hoteldetail, price)
VALUES ('"
.$timestamp."','"
.$packageid."','"
.$uniqueid."','"
.$hotelname."','"
.$roomtype."','"
.$checkin."','"
.$checkout."','"
.$Country."','"
.$Destination."','"
.addslashes($hoteldetail)."','"
.$price."'
)";
// echo "sql- ".print_r($sql);
$stmt = $conn->prepare($sql);
// echo print_r($stmt);
$stmt->execute();
}
}
catch(PDOException $e) {
echo 'ERROR:' . $e->getMessage();
} here

最佳答案

您的 SELECT 查询条件为 WHERE uniqueid=:uniqueid

并且您正在将用户名绑定(bind)到它

$stmt->execute(array(':username'=>$uniqueid));//:username invalid parameter

将其更改为

$stmt->execute(array(':uniqueid'=>$uniqueid));

关于php - 当我在那里使用 if else 时出现 mysql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36623687/

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