试图搜索我的数据库,以便它可以返回我的每一个食谱的成分。然而,当我按下提交按钮,什么都没有出现。
我的数据库有:
recipeName: ....
ing1: ...
ing2:...
ing3:...
etc etc现在,当用户单击“证明”复选框时,它应该会返回该电影,但是我的似乎不起作用。再说一次,我可能犯了一个愚蠢的错误,但任何帮助都会很好。
PHP:
$fields = array('recipe_ing1','recipe_ing2','recipe_ing3');
$query = mysql_query(SELECT * FROM recipe WHERE recipeName LIKE '%".$str."%'");顺便说一句,我知道100%我不应该使用这些功能等,并使用PDO,这是一个迷你项目,我正在努力和我的使用,只有我需要使用这些功能。我将使用最新的命令来完成另一个版本的操作。我想要做的事情的例子:示例
无论如何,在这件事上有任何帮助都是很好的。
发布于 2016-03-16 00:27:36
当您尝试执行查询时:
SELECT * FROM recipe WHERE recipeName LIKE '%".$str."%'"其中$str (例如,当选择Kale时):
recipe_ing1 LIKE '%Kale%' OR recipe_ing2 LIKE '%Kale%' OR recipe_ing3 LIKE '%Kale%'那么完整的查询看起来就像
SELECT * FROM recipe WHERE recipeName LIKE recipe_ing1 LIKE '%Kale%' OR recipe_ing2 LIKE '%Kale%' OR recipe_ing3 LIKE '%Kale%'这是错误的。
您应该将查询更改为:
$query = mysql_query("SELECT * FROM recipe WHERE ".$str) or die("Could not search.");在将值赋值给$str变量时,还应该正确连接:
$str[] = $ign." LIKE '%".mysql_real_escape_string($ingridient)."%'";https://stackoverflow.com/questions/36024305
复制相似问题