我正在尝试在数据库中插入值,但收到以下错误
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>';
答案 0 :(得分:4)
因为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."')";
P.S。我不确定为什么要以不同方式处理某些变量,例如$dob
。您可以使用与$name
相同的语法。
答案 1 :(得分:2)
我修改了你的sql。在你的SQL问题是call.It将工作。
$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`)
values ('$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."')";
谢谢