Forum Moderators: coopster

Message Too Old, No Replies

need help on validation pls

using mysql num rows

         

phlogit

1:57 pm on Jun 18, 2007 (gmt 0)

10+ Year Member



hi i am using the following code to check if the result is present if not display error message.

$num_rows = mysql_num_rows($result);

if ($num_rows == 0){

header(error.php ) /// redirect to error message

}

however this does not seem to work. BUT! when i do this

$num_rows = mysql_num_rows($result);

if ($num_rows > 0){

header(error.php ) /// redirect to error message

}

then it works but for the wrong reason. i need it to redirect to the error message if their is no result e.g. no rows displayed.

what am i doing wrong?

Thanx in advance.

omoutop

2:08 pm on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if ($num_rows > 0)
{
// execute correct code
}
else // =0
{
// redirect to error message
}

bysonary

2:18 pm on Jun 18, 2007 (gmt 0)

10+ Year Member



this is how i check it:

<?
if(mysql_num_rows($result) > 0)
{
header('Location: success.php');
}
else // its not more than 0 so...
{
header('Location: error.php');
}
?>

hope this helps.

phlogit

3:00 pm on Jun 18, 2007 (gmt 0)

10+ Year Member



thanx guys i got it working