大佬教程收集整理的这篇文章主要介绍了在查询中使用PHP变量时出现MySQL错误1064,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP
session_start();
$con = MysqLi_connect("localhost","root","12369","meDical");
$data1 = $_SESSION["symp1"];
$data2 = $_SESSION["symp2"];
$data3 = $_SESSION["symp3"];
$data4 = $_SESSION["symp4"];
$finalData = implode(' ', array($data1, $data2, $data3, $data4));
$userinput = $_requEST["answer"];
$dname=$_SESSION["dname"];
$dname = str_replace(' ', '_', $dName);
echo $dname." <br>";
$sql = " updatE diseases SET UserInput = $finalData WHERE Name = $dname ";
if($userinput=='yes'){
if(MysqLi_query($con,$sql)){
echo "Values inserted";
$_SESSION["info"] = "yes";
header('LOCATIOn: http://localhost/meDical/last.PHP');
}else{
echo MysqLi_errno($con);
$_SESSION["info"] = "no";
//header('LOCATIOn: http://localhost/meDical/last.PHP');
}
}
?>
我收到错误1064?我已经阅读了类似问题的答案,但是我的代码不起作用.我的表架构是:
create table IF NOT EXISTS `diseases` (
`ID` int(50) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`Symptoms` varchar(255) NOT NULL,
`MeDicines` varchar(255) NOT NULL,
`Description` varchar(255) NOT NULL,
`Tags` varchar(255) NOT NULL,
`UserInput` varchar(255) NOT NULL,
PRIMARY KEY (`ID`)
)
我的代码有什么问题?谢谢
解决方法:
更改:
$sql = " updatE diseases SET UserInput = $finalData WHERE Name = $dname ";
至:
$sql = "updatE `diseases` SET `UserInput` = '$finalData' WHERE `name` = '$dname'";
在包含字符串的变量周围添加单引号.
在列和表周围添加反引号以防止MysqL保留字错误
最好使用mysqli_prepare
执行以下操作:
$stmt = MysqLi_prepare($con, "updatE `diseases` SET `UserInput` = ? WHERE `name` = ?");
MysqLi_stmT_Bind_param($stmt, "ss", $finalData, $dName);
MysqLi_stmt_execute($stmt);
以上是大佬教程为你收集整理的在查询中使用PHP变量时出现MySQL错误1064全部内容,希望文章能够帮你解决在查询中使用PHP变量时出现MySQL错误1064所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。