gpt4 book ai didi

php - php 数据更新期间出错

转载 作者:行者123 更新时间:2023-11-29 06:21:52 25 4
gpt4 key购买 nike

$sql = "UPDATE tblprofile SET name = '$membername' ,
f_h_name = '$fathername',
maritalS = '$mstatus' ,
dob = '$dob' ,
occupation = '$occupation' ,
nominee = '$nominee' ,
address1 = '$address1' ,
address2 = '$address2',
city = '$city',
district = '$district',
state = '$state',
pin = '$areapin',
mobile = '$mobileno',
email = '$email',
PANno = '$panno',
bankname = '$bankname',
branch = '$branch',
accountno = '$accountno'
WHERE userId = '$_SESSION['UserId']' "; //line 212
if(mysql_query($sql))
{
echo "Updation Done.";
}

浏览器中出现错误: 解析错误:语法错误,意外的 T_ENCAPSED_AND_WHITESPACE,在第 212 行的 C:\xampp\htdocs\303\saveEditProfile.php 中期待 T_STRING 或 T_VARIABLE 或 T_NUM_STRING

最佳答案

您的variable reference $_SESSION['UserId'] inside the double quoted string is not allowed 。您需要编写 $_SESSION[UserId] (不引用 key ):

"… WHERE userId = '$_SESSION[UserId]' "

或者使用大括号语法{$_SESSION['UserId']}:

"… WHERE userId = '{$_SESSION['UserId']}' "

但我宁愿建议您使用参数化函数来构建查询(例如 sprintf )或准备好的语句,以便您也可以保护自己免受 SQL 注入(inject)。

关于php - php 数据更新期间出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2920200/

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