twistisking Posted May 10, 2007 Share Posted May 10, 2007 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"; } } ?> Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted May 10, 2007 Share Posted May 10, 2007 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 Quote Link to comment Share on other sites More sharing options...
twistisking Posted May 15, 2007 Author Share Posted May 15, 2007 I could still use some help on this if anyone has any opinions Quote Link to comment 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.