PDA

View Full Version : PHP Where and EOF


StealthRT
07-23-2008, 04:19 AM
Hey all i am trying to figure out what i am doing wrong with this code below:

$query = "SELECT * FROM emppcn WHERE LastName = '$userLastName'";
$result = mysql_query($query);

if (!$result) {die("Query failed! Query text: $query<br>Error: " . mysql_error());}

if($result == ''){
echo "Nothing found";
}else{
echo "FOUND!";
}

mysql_close($link);

It keeps saying FOUND! when it really doesn't.... How do i check for EOF instead of the NULL? I know how to do it in ASP (rst.EOF) but i havent found something like that for PHP...

And help would be great! :)

David

PremiumBlend
07-23-2008, 06:20 AM
You're trying to compare the $result object to a string. Since it can't really compare to an empty string, it returns false.

It is an object, so you'll want to call a function like this:

if(mysql_num_rows($result) > 0)

StealthRT
07-23-2008, 08:32 AM
Yep that did it! Thanks! :)

David