2016-02-16 63 views
-4

我正在检查以确认memberid和recipeid都不为空。这样,如果两者都具有价值,它将允许成员将成熟的广告添加到列表中,如果两者都有值,则会告诉他们他们添加的配方已经在列表中。在此工作一段时间需要帮助,并尝试从asp经典转换到php闪烁的微笑。需要查找两条记录中的一条是否为空

$check_fav = mysql_query("SELECT memberid, recipeid FROM favorites WHERE (memberid = '".$memberid."' AND recipeid = '".$id."')"); 

If ($check_fav == TRUE){....... 
+1

[您的脚本存在SQL注入攻击风险。](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) –

+1

请[停止使用' mysql_ *'functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 [这些扩展](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中删除。了解[编写]​​(http://en.wikipedia.org/ wiki/Prepared_statement)语句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart .prepared-statements.php)并考虑使用PDO,[这真的很简单](http://jayblanchard.net/demystifying_php_pdo.html)。 –

+1

喜欢“微笑的笑容”。 –

回答

1

mysql_query()永远不会返回true。如果发生错误,它将返回结果对象或false

那么这就是你打算做测试:

if ($check_fav !== false && mysql_fetch_row($check_fav) !== false) { ... 

但在这之前,请移动到mysqli的功能(或对象符号),而不是mysql_,因为后者已被弃用很长一段时间,并且不再支持PHP7。你也容易受到SQL注入的影响。改为使用prepared statements

+0

我的主人trincot你是一个拯救生命的人,谢谢! – askChuck

+0

10-4会做谢谢 – askChuck

相关问题