gpt4 book ai didi

php - 数据库插入错误

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

我试图在数据库中插入值但出现以下错误

Error: insert into lead (Name,phone,dob,height,weight,source,city,area,address,status,preferred_mode_of_contact,email,email_verified,style,number_of_classes_per_week,days_of_week,time_start,time_end,duration,start_date,description,preferred_trainer_type,price_per_class,price_per_month,call) value ('','','','','','Source 1','','','','','phone','','0','','1','0','','','','','','','','','2015-07-16')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'call) value ('','','','','','Source 1','','','','','phone','','0','','1','0',''' at line 1

我检查过我传递了正确数量的值没有额外的列没有额外的值。“call”列是日期数据类型。当我从插入查询中删除“call”时它工作正常

下面是查询

$sql="insert into lead (Name,phone,dob,height,weight,source,city,area,address,status,preferred_mode_of_contact,email,email_verified,style,number_of_classes_per_week,days_of_week,time_start,time_end,duration,start_date,description,preferred_trainer_type,price_per_class,price_per_month,call)
value ('$name','$phone','".$dob."','$Height','$Weight','$Source','$City','$Area','$Address','$Status','$preferred_mode_of_con','$email','$email_verify','$style','$noc','$day','$time_from','$time_to','$duration','".$ts."','$des','$ptt','$price','$price_month','".$call."')";

if (mysqli_query($conn, $sql))
echo "User registered Sucessfully";
else
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
echo '<br><a href="lead_reg.php">Click Here to go back</a></h3>';

最佳答案

因为 CALL是保留字,如果要将其用作列名,则需要用反引号 (`) 将其括起来。这是您查询的正确形式:

$sql="insert into lead (Name,phone,dob,height,weight,source,city,area,address,status,preferred_mode_of_contact,email,email_verified,style,number_of_classes_per_week,days_of_week,time_start,time_end,duration,start_date,description,preferred_trainer_type,price_per_class,price_per_month,`call`) ".
"value ('$name','$phone','".$dob."','$Height','$Weight','$Source','$City','$Area','$Address','$Status','$preferred_mode_of_con','$email','$email_verify','$style','$noc','$day','$time_from','$time_to','$duration','".$ts."','$des','$ptt','$price','$price_month','".$call."')";

附言我不确定您为什么以不同方式对待某些变量,例如 $dob。您可以使用与 $name 相同的语法。

关于php - 数据库插入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31695528/

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