首页 > 解决方案 > MySQL 查询不正确

问题描述

我不知道为什么以下 MySQL Query 一直失败。它告诉我它的语法无效。它总是在代码的电子邮件区域显示,但没有明显的错误。在将字符串传递到 MySQL 查询之前,我正在清理它们

$query = "INSERT INTO `ToReview` (`number`, `role`, `name`, `email`, `dob`, 
`englishskills`, `previousmember`, `reasonYes`, `whyjoin`, 
`whatcouldyoubring`, `roleplayexperience`, `roleplayexperiencedetail`, 
`commit`, `minimumperiod`) VALUES (NULL, ".$role.", ".$name.", ".$email.", 
".$dob.", ".$englishskills.", ".$previousmember.", ".$reasonYes.", 
".$whyjoin.", ".$whatcouldyoubring.", ".$roleplayexperience.", 
".$roleplayexperiencedetail.", ".$commit.", ".$minimumperiod.");";

$result = mysqli_query($con, $query) or die(mysqli_error($con));

标签: phpmysqlmysqli

解决方案


您正在结束分号处关闭双引号,删除它并重试

$query = "INSERT INTO `ToReview` (`number`, `role`, `name`, `email`, `dob`, 
`englishskills`, `previousmember`, `reasonYes`, `whyjoin`, 
`whatcouldyoubring`, `roleplayexperience`, `roleplayexperiencedetail`, 
`commit`, `minimumperiod`) VALUES (NULL, '$role', '$name', '$email', 
'$dob','$englishskills', '$previousmember', '$reasonYes', 
'$whyjoin', '$whatcouldyoubring', '$roleplayexperience', 
'$roleplayexperiencedetail', '$commit', '$minimumperiod')";

推荐阅读