Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to find is a null is True False

Status
Not open for further replies.

anon1971

Programmer
Aug 9, 2008
88
US
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 ;-).

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

If ($check_fav == TRUE){.......
 
Your query already does the checking for the existence of a recipe, all you need to do is verify whether your query returned a row or not. Checking for true or false will only tell you the query succeeded, but it can succeed even if it did not bring anything back. 0 results would mean the recipe does not exist. At least one result means it already does.

Try:
Code:
$rows = if(mysql_num_rows($check_fav) > 0)
{
[indent][COLOR=#4E9A06]//recipe exists[/color][/indent]
}
else
{
[indent][COLOR=#4E9A06]//recipe does not exist[/color][/indent]
}

PHP Online Manual: mysql_num_rows()



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
The mysql_* functions were deprecated some years ago and don't even exist in the latest version of PHP. It is better to use mysqli_* or PDO.


I'm not a number, I'm a free man
 
Just as a minor point of programming semantics;

Trying to find is a null is True False

A NULL is neither 'true' or 'false', it is simply NULL (equating to Nothing)

So your question should be something like "Testing for a NULL value"

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top