I have a problem.I made a very usable comment section with a database called comment.But when I refresh the page or open it again it copies the comment that I typed for testing.How do I solve that problem.
Repeating comment when refreshed
Collapse
X
-
Okay then, here are the codes.
Code:<form action="<?php $_PHP_SELF ?>" method="POST"> Name: <input type="text" name="name" required="required" placeholder="eg. tox!c or benz" /><br/><br/> E-mail: <input type="text" name="email" required="required" placeholder="eg. toxic5@gmail.com" /><br/><br/> Comments : <br/> <textarea required="required" title="Comments" rows="5" cols="50" name="comment" placeholder="Any comment welcomed..."> </textarea> <input style="display: inline-block; background:transparent; max-width: 200px; margin: 50px 10px 30px 10px; padding: 10px; color: #000; border:1px solid #000; cursor:pointer; text-align: center;" type="submit" name="submit" value="Leave comment" onclick="Thank();"/> </form> <div style="background:lavenderblush;max-width:60em;position:relative; left:30px;box-shadow:2px 2px 2px #aaa;"> <div style="background:#e9967a;"><br/></div> <h1>Comments</h1> <? include("connect.php"); if(isset($_POST['submit'])) { $e=$_POST['email']; $n=$_POST['name']; $c=$_POST['comment']; $insert=mysql_query("use codb"); $insert=mysql_query("insert into comment (name,email,comment) values ('$n','$e','$c')")or die(mysql_error()); } $select = mysql_query("select * from comment" ); while ( $row = mysql_fetch_array ( $select )) { echo '<h3 class="h3">'.$row [ 'name' ].'</h3>'; echo '<i>'.$row [ 'comment' ].'</i><br/>'; echo "<br /><hr/>"; } ?>
Comment
-
Hi again, i've updated the codes to the comment section but still repeating. The newer codes are
Code:<!-- HTML FORM --> <h3>Leave a comment</h3> <form action="<?php $_PHP_SELF ?>" method="POST"> Name: <input type="text" name="name" required="required" placeholder="eg. tox!c or benz" maxlength="25" /><br/><br/> Comments : <br/> <textarea required="required" title="Comments" rows="10" cols="50" name="comment" placeholder="Any comment welcomed..."> </textarea> <input style="display: inline-block; background:transparent; max-width: 200px; margin: 50px 10px 30px 10px; padding: 10px; color: #000; border:1px solid #000; cursor:pointer; text-align: center;" type="submit" name="submit" value="Comment" /> </form> <div style="background:#fff0f5; max-width:80%; margin-left:7%; box-shadow:2px 2px 2px #aaa; color:#000;"> <div style="background:#e9967a;"><br/></div> <h1>Comments</h1> <!-- INSERT COMMENT TO DATABASE --> <?php include('connect.php'); #connect to CODB #Assign variables $name = $_POST['name']; $ip = $_SERVER['REMOTE_ADDR']; $comment = $_POST['comment']; $submit = $_POST['submit']; #check if the user has input and store it in COMMENTS else echo out NOT INSERTED if( isset($submit) ) { $insert = @mysql_query("USE codb"); $insert = @mysql_query("INSERT INTO comment (ip,name,comment) VALUES ('$ip','$name','$comment') "); echo '<span style="color:#000;background:rgba(30, 250, 30, 0.1);border:1px solid #0f0;">Inserted</span>'; }else { echo '<span style="color:#f00;background:rgba(250, 10, 10, 0.3);border:1px solid #f00;">Please fill out all the fields correctly</span>'; } ?> <!-- PREVIEW COMMENTS --> <?php include('connect.php'); #connect CODB #Assign variables $s = date("d/m/y h:i:s"); #Assign the date of input $getquery = mysql_query("SELECT * FROM comment ORDER BY id DESC LIMIT 70")or die(mysql_error()); #get comments #Check if there are comments and preview them while ($rows = mysql_fetch_assoc($getquery)) { $id = $rows['id']; $s = $rows['submission_date']; $name = $rows [ 'name' ]; $comm = $rows ['comment']; echo "<br/>$id . <h3 style=\"font-size:25px;\">$name</h3>"; echo "<i>$s<br/><br/></i>"; echo "$comm<br/><br /><hr/>"; } ?>
Comment
-
Yeah, i've already figured that out. It inserts, fetches and displays the last comment when refreshed. I've read a blog about making comments and at the last part he said that he edited the codes because it was repeating and that he highlighted the line, but i didn't see any highlighted line, maybe because i was using my phone, and when i tried to ask him to write the codes on the comment the page displays blank as if the blog was deleted. Any idea how i can solve this problem??? tnxComment
Comment