Jump to content

Comments php


twistisking

Recommended Posts

So me and a friend have been working on this comment page script and I got ever thing work except for one portion. After a comment is left on the page and the page reloads, I get an error. I have been trying to fix it but I haven't had any luck. If anyone could help I would very much appreciate it. I added some guidelines incase anyone wants to use this script as well. Here is the code we created:

 

 

<?

 

 

if (isset($_REQUEST["txtName"]) && isset($_REQUEST["txtComments"])) {

 

  $name = addslashes($_REQUEST["txtName"]);  // make quotes, apostrophes, etc safe for the DB query

 

  // if they put in an e-mail address, store it in the DB, otherwise put in a blank string

  if (isset($_REQUEST["txtEmail"])) {

    $email = addslashes($_REQUEST["txtEmail"]);  // make quotes, apostrophes, etc safe for the DB query

  } else {

    $email = "";

  }

 

  $comment = strip_tags($_REQUEST["txtComments"],"<b><i>");  // remove any HTML besides bold and italic tags

  $comment = addslashes($comment); // make quotes, apostrophes, etc safe for the DB query

  $comment = str_replace("\n","<br>\n",$comment); // turn line breaks into HTML line breaks

 

  $id = $_REQUEST["id"];

  if (!is_numeric($id)) {

    echo "The article specified does not exist!";

  } else {

    @require_once("database.php");

    $sql = "INSERT INTO comments (article,name,email,comment) VALUES ('$id','$name','$email','$comment')";

    mysql_query($sql);

    if (mysql_error()) {

      echo "There was an error storing your comment in the database!";

    }

  }

}

 

 

 

 

 

if (!isset($_REQUEST["id"])) {

  echo "There was an error displaying this page.";

  exit();

}

if ($_REQUEST["id"] == "" || !is_numeric($_REQUEST["id"])) {

  echo "There was an error displaying this page.";

  exit();

}

 

define("ARTICLE_ID",$_REQUEST["id"]);

@require_once("../posttest.php");

 

@require_once("database.php");

$sql = "SELECT * FROM comments WHERE article='" . $_REQUEST["id"] . "' ORDER BY datetime DESC";

$result = mysql_query($sql);

if (mysql_errno()) {

  echo "<div class='comment'>There was an error retrieving the comments from the database: </div>" . mysql_error();

} else {

  if (mysql_num_rows($result) == 0) {

    echo "<div class='comment'>There are currently no comments for this article.</div>";

  }

  $x = 0;

  while ($data = mysql_fetch_assoc($result)) {

    if ($x == 0) {

      echo "<div class='comment_top'>\n";

      $x = 1;

    } else {

      echo "<div class='comment'>\n";

    }

    if ($data['email'] != "") {

      $link = "<a href='mailto:".stripslashes($data['email'])."' class='name'>".stripslashes($data['name'])."</a>";

    } else {

      $link = "<span class='name'>".stripslashes($data['name'])."</span>";

    }

    echo $link." <span class='cdate'>".$data['datetime']."</span><br><br>\n";

    echo "<div style='text-align:left'>";

    echo stripslashes($data['comment']);

    echo "</div>\n</div>\n";

  }

}

 

?>

Link to comment
Share on other sites

ok,

 

 

justy quickly without reading the code......

 

 

if your looking for a way to submit something, on a refresh, however not allow duplicates ( like refreshing etc.)  then why not do a function, where it does it, and then relocates using javascript, like window.location = "domain.com/thing.php" and then echo out a line, for browsers that dont allow javascript.....

 

 

basically what youd be wanting to acheive, is the function, to do stuff, and relocate the user, however to the same page, so that the GET data or whatever, is reset.

 

 

gdlk

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.