Jump to content

MySQL Query Isn't Working... I think.


Altec

Recommended Posts

Yay for simple, simple mistakes I make!

<?php
if(isset($_POST['flag'])) {
     $id = (int)$_POST['comment']; $entry_id = (int)$_POST['entry'];
     require_once('recaptchalib.php');
     $privatekey = "rawr";
     $resp = recaptcha_check_answer ($privatekey,
                                     $_SERVER["REMOTE_ADDR"],
                                     $_POST["recaptcha_challenge_field"],
                                     $_POST["recaptcha_response_field"]);

     if (!$resp->is_valid) {
       die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
            "(reCAPTCHA said: " . $resp->error . ")");
     }
     mysql_connect ('localhost', 'rawr', 'rawr') ;
     mysql_select_db ('rawr');
     $timestamp = strtotime("now");
     $result = mysql_query("UPDATE comments SET status='flagged', flagged_date='$timestamp' WHERE id='$id' AND entry='$entry_id'") or print ("There was an error flagging the comment.".mysql_error());
     if ($result != false) {
         print "<p>Thank you. Comment ID: $id under Entry: $entry_id has been flagged. It has been added to the moderation queue and will be handled shortly.</p>";
     }
}
else {
     mysql_connect ('localhost', 'rawr', 'rawr') ;
     mysql_select_db ('rawr');

     if (!isset($_GET['id']) || !is_numeric($_GET['id']) || !isset($_GET['entry']) || !is_numeric($_GET['entry'])) {
          die("Invalid ID specified.");
     }
     $id = (int)$_GET['id']; $entry_id = (int)$_GET['entry'];
     $sql2 = "SELECT status FROM comments WHERE id='$id' AND entry='$entry_id' LIMIT 1";
     if (mysql_query($sql2 == 'public')) {
     $sql = "SELECT * FROM comments WHERE id='$id' AND entry='$entry_id' LIMIT 1";
     $result = mysql_query($sql) or die("Can't select comment from table comments.<br />" . $sql . "<br />" . mysql_error());
     while($row = mysql_fetch_array($result)) {
          $id = stripslashes($row['id']);
          $entry = stripslashes($row['entry']);
          $name = stripslashes($row['name']);
          $url = stripslashes($row['url']);
          $comment = stripslashes($row['comment']);
          $timestamp = date("l, F d, Y", $row['timestamp']);
?>
<p>Below is the comment you have chosen to flag. This feature is to be used ONLY to flag the following type(s) of comments: spam, advertising messages, and problematic (harassment, fighting, or rude) comments.</p>
<hr />
<?php echo $name; ?> | URL: <?php echo $url; ?>
<blockquote><p><?php echo $comment; ?></p></blockquote>
Entry ID: <?php echo $entry; ?> | Comment ID: <?php echo $id; ?> | Date: <?php echo $timestamp; ?>
<hr />
<br />
<p>Please solve the following CAPTCHA (to prevent misuse of this feature) and click "Flag This Comment."</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
     <p>
          <?php
          require_once('recaptchalib.php');
          $publickey = "rawr";
          echo recaptcha_get_html($publickey);
          ?><br /><br />
     </p>
     <p>
          <input type="hidden" name="comment" id="comment" value="<?php echo $id; ?>" />
          <input type="hidden" name="entry" id="entry" value="<?php echo $entry_id; ?>" />
          <input type="submit" name="flag" id="flag" tabindex="2" value="Flag This Comment" />
     </p>
</form>
<?php
     }
   }
   else {
     echo '<p>The comment you have chosen to flag has already been flagged. It will be moderated shortly.</p>';
   }
}
?>

The above code is my script to flag a comment. It worked perfectly before I added these lines:

     $sql2 = "SELECT status FROM comments WHERE id='$id' AND entry='$entry_id' LIMIT 1";
     if (mysql_query($sql2 == 'public')) {
// ........
}

I was hoping that would check if the comment has not been flagged before. However, every single public comment I try to flag I can't because this says it is already flagged. I see no problem with the code... Anyone?

 

mod edit: code tags added.

Link to comment
https://forums.phpfreaks.com/topic/102084-mysql-query-isnt-working-i-think/
Share on other sites

check this out man

$sql2 = "SELECT status FROM comments WHERE id='$id' AND entry='$entry_id' LIMIT 1";

    if (mysql_query($sql2 == 'public')) {

// ........

}

your this code is just a query.not fetching a data from database.u need to fetch data from database and then check it in while loop or whtever u prefer.get it?

like this:

$sql6 = "SELECT * from  currencies  WHERE currencies_id ='$currencyid' ";

$result2=dbQuery($sql6);

while($row = dbFetchAssoc($result2))

{

  extract($row);

  if (mysql_query($sql2 == 'public')) {

// ........

  }

}

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.