Jump to content

If statement - hair pull out *SOLVED*


highaspen

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
Link to comment
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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.