spiceydog Posted July 17, 2008 Share Posted July 17, 2008 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; } Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/ Share on other sites More sharing options...
l0ve2hat3 Posted July 17, 2008 Share Posted July 17, 2008 if ($count = '0') you need == instead of = Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/#findComment-592187 Share on other sites More sharing options...
spiceydog Posted July 17, 2008 Author Share Posted July 17, 2008 Hmm well that didn't fix it but I deffinetly needed that! thanks anyway! anyone else? Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/#findComment-592199 Share on other sites More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 Your query should be failing because its not valid for starters. Are you getting any errors? Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/#findComment-592201 Share on other sites More sharing options...
spiceydog Posted July 17, 2008 Author Share Posted July 17, 2008 if by invalid you mean incomplete then yes I'm aware of that, I didn't post the ENTIRE script just the important part. I'm not getting any errors, it's just not opening an alert box. I do believe however that the exit; is working. Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/#findComment-592210 Share on other sites More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 I do believe however that the exit; is working. Then it would seem you have a javascript issue. By the way, integers are not surrounded by quotes. if ($count == 0) { Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/#findComment-592213 Share on other sites More sharing options...
spiceydog Posted July 17, 2008 Author Share Posted July 17, 2008 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 Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/#findComment-592224 Share on other sites More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 Once again, that query will not work. Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/#findComment-592225 Share on other sites More sharing options...
spiceydog Posted July 17, 2008 Author Share Posted July 17, 2008 But why thorpe? Why won't my query work? Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/#findComment-592229 Share on other sites More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 Actually it very well may work, just looks a bit backward. Most would write... $checkuser = "SELECT * FROM users WHERE username = '$to'"; Where is $to defined? Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/#findComment-592232 Share on other sites More sharing options...
spiceydog Posted July 17, 2008 Author Share Posted July 17, 2008 To is simply defined by: $postto = mysql_real_escape_string(trim($_POST['to'])); $bad = array("<", ">", "="); $bitch = array("no", "no", "no"); $to = str_replace($bad, $bitch, $postto); Link to comment https://forums.phpfreaks.com/topic/115163-for-some-reason-my-if-statement-isnt-working/#findComment-592241 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.