我目前正试图更新我的数据库中的特定记录,尽管我已经彻底检查了语法chrome告诉我,我在某处出错了。MYSQL更新查询语法问题
任何建议,将不胜感激
$title = $_POST["title"];
$alttext = $_POST["alttext"];
$description = $_POST["description"];
$price = $_POST["price"];
$id = $_POST["ID"];
$insertQuery = "UPDATE cmsproducts SET Title = '$title', Alt_Text = '$alttext', Source = '$target_path', Description = '$description', Price = $price WHERE ID = $id";
// Save the form data into the database
if ($result = $connector->query($insertQuery)){
// It worked, give confirmation
echo '<center><b><span style="color: #FF0000;">Product added to the database</span></b></center><br /><br />';
}else{
// It hasn't worked so stop. Better error handling code would be good here!
echo('<center>Sorry, there was an error saving to the database</center>');
echo "<center><b>File Name:</b> ".$target_path."<br/>";
die(mysql_error());
}
我试图查询不变量来检查它是否是一个问题存在,但它仍然在我尖叫错误:
对不起,有一个保存到数据库时出错 您的SQL语法有错误;请检查与您的MySQL服务器版本相对应的手册,以便在测试中使用正确的语法,Source = ../images/Pictures /,Description = This is a test image of test'at line 1
回显您的$ insertQuery变量并检查最终查询。也许有些东西是空的或有任何格式/编码问题,谁知道(你没有检查POST输入的方式,这是一个安全问题)。 – Alfabravo 2011-04-19 19:17:45
我们无法帮助您,直到您告诉我们“post”变量中传递的内容以及数据库模式的外观。你也必须防止SQL注入! – ohmusama 2011-04-19 19:20:17
这也是一个安全问题。您可能想要使用mysql_real_escape_string或其他方式来防止SQL注入攻击。 – 2011-04-19 19:21:28