Help - Search - Members - Calendar
Full Version: [resolved] Edit / Delete Comments Help
Codegrrl.com Forums > Script Help > Tutorial Help
Phenix
For Some Reason I Keep Getting This Error Message And I'm Not Sure Why :

CODE
Can't select comments.

Unknown column 'entry' in 'field list'
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mnt/w0603/d08/s07/b025e6a3/www/vintage/blog/delete_comments.php on line 62


Here's My Code :

CODE

<?php
mysql_connect ('****', '****', '****');
mysql_select_db ('****');

if (isset($_POST['edit'])) {
    $name = htmlspecialchars(strip_tags($_POST['name']));
    $email = htmlspecialchars(strip_tags($_POST['email']));
    $url = htmlspecialchars(strip_tags($_POST['url']));
    $comment = htmlspecialchars(strip_tags($_POST['comment']));
    $comment = nl2br($comment);
    $id = (int)$_POST['id'];

    if (!get_magic_quotes_gpc()) {
        $name = addslashes($name);
        $url = addslashes($url);
        $comment = addslashes($comment);
    }

    $result = mysql_query("UPDATE blog_comments SET name='$name', email='$email', url='$url', comment='$comment' WHERE id='$id' LIMIT 1") or print ("Can't update comment.<br />" . $result . "<br />" . mysql_error());
    if ($result != false) {
        print "<p>The comment has successfully been edited!</p>";
    }
}

if(isset($_POST['delete'])) {
$id = (int)$_POST['id'];
     $result = mysql_query("DELETE FROM blog_comments WHERE id='$id' LIMIT 1") or print ("Can't delete comment.<br />" . $result . "<br />" . mysql_error());
     if ($result != false) {
         print "<p>The comment has successfully been deleted!</p>";
     }
}

if (isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id'])) {

$result = mysql_query ("SELECT * FROM blog_comments WHERE id='$_GET[id]'") or print ("Can't select comment.<br />" . mysql_error());

while ($row = mysql_fetch_array($result)) {
      $old_name = stripslashes($row['name']);
      $old_email = $row['email'];
      $old_url = stripslashes($row['url']);
      $old_comment = stripslashes($row['comment']);
      $old_comment = str_replace('<br />', '', $old_comment);
}

?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <p><input type="hidden" name="id" id="id" value="<?php echo $_GET['id']; ?>">
    <strong><label for="name">Name:</label></strong> <input type="text" name="name" id="name" size="40" value="<?php echo $old_name; ?>" /></p>
    <p><strong><label for="email">E-mail:</label></strong> <input type="text" name="email" id="email" size="40" value="<?php echo $old_email; ?>" /></p>
    <p><strong><label for="url">URL:</label></strong> <input type="text" name="url" id="url" size="40" value="<?php echo $old_url; ?>" /></p>
    <p><strong><label for="comment">Comment:<label></strong><br />
    <textarea cols="80" rows="20" name="comment" id="comment"><?php echo $old_comment; ?></textarea></p>
    <p><input type="submit" name="edit" id="edit" value="Save Changes"> <input type="submit" name="delete" id="delete" value="Delete Comment"> <input type="submit" value="Never Mind"></p>
</form>
<?php

}
else {

$result = mysql_query("SELECT entry AS get_group FROM blog_comments GROUP BY get_group DESC LIMIT 10") or print ("Can't select comments.<br />" . $result . "<br />" . mysql_error());

while($row = mysql_fetch_array($result)) {
     $get_group = $row['get_group'];

     print "<p>";

    $result2 = mysql_query("SELECT timestamp, title FROM blog WHERE id='$get_group'");
    while($row2 = mysql_fetch_array($result2)) {
        $date = date("l F d Y",$row2['timestamp']);
        $title = stripslashes($row2['title']);
        print "<strong>" . $date . " - " . $title . "</strong><br />";
    }

    $result3 = mysql_query("SELECT * FROM blog_comments WHERE entry='$get_group' ORDER BY timestamp DESC");
    while($row3 = mysql_fetch_array($result3)) {
        $id = $row3['id'];
        $name = stripslashes($row3['name']);
        $comment = stripslashes($row3['comment']);
        $date = date("l F d Y",$row3['timestamp']);

        if (strlen($comment) > 75 || strstr($comment, "<br />") || strstr($comment, "\n")) {
            $comment = substr($comment,0,75) . "...";
            $comment = str_replace("<br />", "", $comment);
            $comment = str_replace("\n", " ", $comment);
        }

        print "<a href=\"delete_comments.php?id=" . $id . "\">" . $comment . "</a><br />Comment by " . $name . " @ " . $date;
        print "</p>";

    }
}
}
mysql_close();

?>


Any Help Would Be Much Appreciated Because I've Been Working On This For A Minute And Have NO Clue What I'm Doing Wrong. Please and Thanks VERY MUCH!!
Amelie
When you created your comments table, what fields did you use? What the error is saying is that you're asking it to get something called "entry" from the database, but you don't have any fields by that name.
Phenix
DUH! [ smack forehead ] Thanks I fixed it! flowers.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.