Jump to content

For some reason my "if" statement isn't working?


spiceydog

Recommended Posts

I have this simple if statement below that is supposed to open a javascript popup if the query doesn't return any lines. It doesn't however it does seem to run the exit; because script further down on the webpage that is supposed to post the data does not run if $count = 0.

 

$checkuser = "SELECT * FROM users WHERE '$to'=username";
  $count1 = mysql_query($checkuser) or die(mysql_error());
  $count = mysql_num_rows($count1) or die(mysql_error());
if ($count = '0') {
echo "<script language='JavaScript' type='text/javascript'>alert('There is no user with that name'); 
  history.go(-1);</script>";
exit;
}

Ok it turns out I did have a javascript problem but that didn't matter because this doesn't work either:

$checkuser = "SELECT * FROM users WHERE '$to'=username" or die(mysql_error());
$count1 = mysql_query($checkuser) or die(mysql_error());
$count = mysql_num_rows($count1) or die(mysql_error()); 
  if ($count == 0) {
echo "There is no user named $to";
exit;
}

 

I am sure that count SHOULD be = 0 because $to is just a field that is submitted

Archived

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

×
×
  • 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.