-4

I am trying to check to confirm that both memberid and recipeid is not null. That way if both have value it will allow the member to ad the ripe to there list if both have a value it will tell them the recipe they are adding is already in there list. Working on this for a while need help and trying to transition from asp classic to php winky smile.

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

If ($check_fav == TRUE){.......
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
askChuck
  • 1
  • 1
  • 1
    [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Feb 16 '16 at 20:31
  • 1
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Feb 16 '16 at 20:31
  • 1
    Love the "winky smile". – Jay Blanchard Feb 16 '16 at 20:32
  • am trying to check to confirm that both memberid and recipeid is not null. That way if both have different value (memberid is not null and recipeid IS NULL)it will allow the member to ad the recipe to there list; if both have a value it will tell them the recipe they are adding is already in there list. Working on this for a while need help and trying to transition from asp classic to php smile. – askChuck Feb 16 '16 at 20:41

1 Answers1

1

mysql_query() never returns true. It returns a result object or false if an error occurred.

So this is the test you intended to do:

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

But before you do this, please move to mysqli functions (or object notation) instead of mysql_, as the latter are deprecated for ages now and no longer supported in PHP7. Also you are vulnerable to SQL injection. Use prepared statements instead.

trincot
  • 317,000
  • 35
  • 244
  • 286