zeroblitzt Posted August 5, 2006 Share Posted August 5, 2006 Hey all, I have this block of code used to mark inappropriate messages on my message board. Thing is, I need to check if a user has already marked a message once, so I do that with this line:[quote] $checkusrx = mysql_query("SELECT * FROM reports WHERE marker = ".$u['userid']." AND msgid = ".$msgid."");[/quote]Unfortunately this does not work. I always either get either nothing (the page stays exactly the same and doesn't seem to update, even though it should be) or the error message I crafted, that says "You may not mark a message more than once". Thing is, the marked message queue is currently empty so there is no way I could have marked something already.Here is the code below. The problem (I think) is in between lines 4 and 10. Any help would really be appreciated, I just spent an hour trying different ways to do this but none have worked so far.[quote]if ($action == "r"){ $msgid = $_GET['msg']; $checkusrx = mysql_query("SELECT * FROM reports WHERE marker = ".$u['userid']." AND msgid = ".$msgid.""); if ($checkusrx == FALSE) { $checkmsgx = mysql_query("SELECT * FROM reports WHERE msgid = ".$msgid.""); if ($checkmsgx == FALSE) { $reportx = mysql_query("INSERT INTO reports (`msgid`, `marker`) VALUES ('$msgid', '".$u['userid']."')"); if ($reportx) { echo "<span class='boardbar2'>Thank you, this message has been marked for moderation.</span>"; } else { echo "<span class='error'>Error: Could not complete moderation - ".mysql_error()."</span>"; } } else { $marknumx = mysql_query("SELECT marks FROM reports WHERE msgid = ".$msgid.""); $marknum = mysql_fetch_assoc($marknumx); $uprepx = mysql_query("UPDATE reports SET marks = '". $marknum['marks']+1 ."' WHERE msgid = ".$msgid.""); if ($uprepx) { echo "<span class='boardbar2'>This message has already been reported, so your report has been merged. Thank you.</span>"; } } } else { echo "<span class='error'>ERROR: You may only mark a message once.</span>"; }}[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/16667-multiple-where-statement-in-mysql_query-not-working/ Share on other sites More sharing options...
king arthur Posted August 5, 2006 Share Posted August 5, 2006 You're using double quotes inside double quoted strings for your queries, and because you are not adding "or die(mysql_error())" on the end of the call to mysql_query() you are not catching the syntax errors. Use single quotes inside the strings instead. Quote Link to comment https://forums.phpfreaks.com/topic/16667-multiple-where-statement-in-mysql_query-not-working/#findComment-69981 Share on other sites More sharing options...
zeroblitzt Posted August 5, 2006 Author Share Posted August 5, 2006 Just to clarify, do you mean I should take:[quote] $checkusrx = mysql_query("SELECT * FROM reports WHERE marker = ".$u['userid']." AND msgid = ".$msgid."");[/quote]And make it into:[quote] $checkusrx = mysql_query('SELECT * FROM reports WHERE marker = '.$u['userid'].' AND msgid = '.$msgid.'');[/quote]OR do you mean I should do this:[quote] $checkusrx = mysql_query("SELECT * FROM reports WHERE marker = $u['userid'] AND msgid = $msgid");[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/16667-multiple-where-statement-in-mysql_query-not-working/#findComment-69983 Share on other sites More sharing options...
king arthur Posted August 5, 2006 Share Posted August 5, 2006 Sorry, forget that, it was the "" at the end of the queries that was confusing me..... Quote Link to comment https://forums.phpfreaks.com/topic/16667-multiple-where-statement-in-mysql_query-not-working/#findComment-69985 Share on other sites More sharing options...
king arthur Posted August 5, 2006 Share Posted August 5, 2006 The thing is, you're not actually checking the number of rows returned - I think if mysql_query doesn't return false it does not necessarily mean any rows were returned. Quote Link to comment https://forums.phpfreaks.com/topic/16667-multiple-where-statement-in-mysql_query-not-working/#findComment-69986 Share on other sites More sharing options...
zeroblitzt Posted August 5, 2006 Author Share Posted August 5, 2006 Well I just changed it to [quote] $checkusrx = mysql_query("SELECT * FROM reports WHERE marker = ".$u['userid']." && msgid = ".$msgid."") or die(mysql_error()); $checkusr = mysql_fetch_assoc($checkusrx); if (!$checkusr) {[/quote]But still nothing (as in its not giving me an Mysql error message or one of my own error messages). Quote Link to comment https://forums.phpfreaks.com/topic/16667-multiple-where-statement-in-mysql_query-not-working/#findComment-69987 Share on other sites More sharing options...
king arthur Posted August 5, 2006 Share Posted August 5, 2006 Try putting some stand-alone echo statements in various places to find out what it actually is doing. Quote Link to comment https://forums.phpfreaks.com/topic/16667-multiple-where-statement-in-mysql_query-not-working/#findComment-69988 Share on other sites More sharing options...
zeroblitzt Posted August 5, 2006 Author Share Posted August 5, 2006 Yep, I did and I found the problem: Seems you were right about the mysql_query not returning FALSE everywhere, because in another query I do the same thing (check to see if its false) and it wasnt coming up. I got it sorted now, everything seems to be working too :DThanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/16667-multiple-where-statement-in-mysql_query-not-working/#findComment-69989 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.