为什么PHP将我的查询代码评估为假?

时间:2019-01-09 11:28:42

标签: php sql xampp

我不明白为什么我的查询无法正常工作

$sql = "UPDATE rezepte Set namerecipe =" .$namerecipe .",ingredient1 =" . $ingredient1 . ",ingredient2 =" . $ingredient2 . ",ingredient3 =" . $ingredient3 . ",ingredient4 =" . $ingredient4 . ",ingredient5 =" . $ingredient5 . ",ingredient6 =" . $ingredient6 . ",ingredient7 =" . $ingredient7 . ",ingredient8 =" . $ingredient8 . ",ingredient9 =" . $ingredient9 . ",ingredient10 =" . $ingredient10 . ", preparation =" . $preparation . ", cathegory1 =" . $cathegory1 . ", cathegory2 = " . $cathegory2 . ", cathegory3 = " . $cathegory3 . ", difficulty = " . $difficulty . ",time = " . $time . ", amount = " .$amount . ", source =" . $source . " WHERE ID=" . $id ."";

我知道某些变量的英文字母D不正确:

PHP给出以下错误消息:

  

“错误:无法执行UPDATE rezepte Set namerecipe   =,成分1 =,成分2 =,成分3 =,成分4 =,成分5 =,成分6 =,成分7 =,成分8 =,成分9 =,成分10 =,准备=,cathegory1 =,cathegory2 =,cathegory3 =,难度=,时间=,数量=,来源=汤姆WHERE ID = 18。你有一个   您的SQL语法错误;检查与您的手册相对应的手册   MariaDB服务器版本可在'ingredient1附近使用正确的语法   =,ingredient2 =,ingredient3 =,ingredient4 =,ingredient5 =,第1行的成分'

但是我没有找到错误

1 个答案:

答案 0 :(得分:-1)

此问题并非完全重复,但可以通过研究该问题的最高答案找到解决问题的方法:How can I prevent SQL injection in PHP?

  • 您的代码容易受到SQL注入的影响,而解决该问题也将解决您的查询错误。 (将东西设置为绝对不等于是SQL中的语法错误,最接近的合法值为NULL或空字符串)