Jump to content

Multiple "WHERE" statement in mysql_query() not working.


zeroblitzt

Recommended Posts

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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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).
Link to comment
Share on other sites

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 :D

Thanks for the help.
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.