mysql_query WHERE`id` =' $ user' &安培;&安培; ' $交'

时间:2017-07-03 20:38:03

标签: php mysql

所以我有一个看起来像这样的mysql查询。

$copy = mysql_query("SELECT `id` FROM `brain` WHERE `id` = '$user_screen_name' && '$posts['title']'");

我希望查询搜索表格中的ID,其中屏幕名称和帖子标题字符串匹配,并将找到的ID放在变量中。我该怎么做?

1 个答案:

答案 0 :(得分:2)

首先,一些警告:

请在PHP 7中删除stop using mysql_* functions These extensions。了解prepared PDO语句和MySQLi并考虑使用PDO,it's really pretty easy

Little Bobby your script is at risk for SQL Injection Attacks. 。即使escaping the string也不安全!

要修复您的查询,您需要为要过滤的每个项目单独AND条件:

WHERE `id` = '$user_screen_name' 
AND `title` = '$posts["title"]'

如果没有看到你的表格布局,就很难进一步发展,但如果你想在变量中使用id,你可以在查询之后执行

$row = mysql_fetch_array($copy);

完成后,$row['id']将成为包含id的变量。