Jump to content

Archived

This topic is now archived and is closed to further replies.

highaspen

If statement - hair pull out *SOLVED*

Recommended Posts

okay, I've tried writting this several different ways each not working. I'm sure it's something stupid. Here is what I've got.

------------------------
$rs=mysql_query($sql,$conn)
or die("Could not execute query");

if (!$rs){
include ("somepage.php");
exit();}

else{ then I've got a bunch of code here. }
------------------------

The problem I'm having is, the if statment is continually ignored and only displays the else. I've rigged the database so that the if statment will be true, yet it still fails. I've also tried this using if ($rs == "null") with the same results. And if($rs==NULL).

Any help would place the helper in GOD status in my mind.

Thanks

Share this post


Link to post
Share on other sites
mysql_query only returns false if the query fails beacause of an error.

Are you expecting $rs to be false because no records are returned. Returning no records is not an error. To check that condition you need

[code]
<?php
$rs=mysql_query($sql,$conn)
      or die("Could not execute query");
     
if (mysql_num_rows($rs)==0){
    include ("somepage.php");
    exit();
}

else {
        // then I've got a bunch of code here.
}
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.