473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Repeating comment when refreshed

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.
Nov 29 '15 #1
10 2285
zmbd
5,501 Expert Mod 4TB
Have you checked the code that is being ran on the page-load?
Nov 29 '15 #2
YES!Over and over again.But I don't see anything suspicious.
Dec 2 '15 #3
Rabbit
12,516 Expert Mod 8TB
Well, it's a little hard for us to say what's wrong without any code to look at.
Dec 2 '15 #4
Okay then, here are the codes.
Expand|Select|Wrap|Line Numbers
  1. <form action="<?php $_PHP_SELF ?>" method="POST">
  2. Name: <input type="text" name="name" required="required" placeholder="eg. tox!c or benz" /><br/><br/>
  3. E-mail: <input type="text"  name="email" required="required" placeholder="eg. toxic5@gmail.com" /><br/><br/>
  4. Comments : <br/>
  5. <textarea required="required" title="Comments" rows="5" cols="50" name="comment" placeholder="Any comment welcomed...">
  6. </textarea>
  7. <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();"/>
  8. </form>
  9.  
  10. <div style="background:lavenderblush;max-width:60em;position:relative; left:30px;box-shadow:2px 2px 2px #aaa;">
  11. <div style="background:#e9967a;"><br/></div>
  12. <h1>Comments</h1>
  13.  
  14.  
  15. <?
  16. include("connect.php");
  17. if(isset($_POST['submit']))
  18. {
  19. $e=$_POST['email'];
  20. $n=$_POST['name'];
  21. $c=$_POST['comment'];
  22. $insert=mysql_query("use codb");
  23. $insert=mysql_query("insert into comment
  24. (name,email,comment)
  25. values ('$n','$e','$c')")or die(mysql_error());
  26. }
  27. $select = mysql_query("select * from comment" );
  28. while ( $row = mysql_fetch_array ( $select )) {
  29. echo '<h3 class="h3">'.$row [ 'name' ].'</h3>';
  30. echo '<i>'.$row [ 'comment' ].'</i><br/>';
  31.  
  32. echo "<br /><hr/>"; 
  33. }
  34.  
  35. ?>
  36.  
Dec 24 '15 #5
Rabbit
12,516 Expert Mod 8TB
How come you're inserting into table comment but reading from table comment4?
Dec 24 '15 #6
It was just a mistake I made when pasting it.So I'm guessing the problem is that every time the page loads, the code fetches the data from the database and echo it.Now how do I make the php codes not to duplicate it after reloading???
Dec 26 '15 #7
Hi again, i've updated the codes to the comment section but still repeating. The newer codes are
Expand|Select|Wrap|Line Numbers
  1.  <!--   HTML FORM   -->
  2.  
  3.  
  4.  
  5. <h3>Leave a comment</h3>
  6.  
  7. <form action="<?php $_PHP_SELF ?>" method="POST">
  8. Name: <input type="text" name="name" required="required" placeholder="eg. tox!c or benz" maxlength="25" /><br/><br/>
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. Comments : <br/>
  19. <textarea required="required" title="Comments" rows="10" cols="50" name="comment" placeholder="Any comment welcomed...">
  20. </textarea>
  21.  
  22. <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" />
  23. </form>
  24.  
  25.  
  26.  
  27. <div style="background:#fff0f5; max-width:80%; margin-left:7%; box-shadow:2px 2px 2px #aaa; color:#000;">
  28. <div style="background:#e9967a;"><br/></div>
  29. <h1>Comments</h1>
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. <!--   INSERT COMMENT TO DATABASE   -->
  37.  
  38. <?php
  39. include('connect.php');   #connect to CODB
  40.         #Assign variables 
  41. $name = $_POST['name'];
  42. $ip = $_SERVER['REMOTE_ADDR'];
  43. $comment = $_POST['comment'];
  44. $submit = $_POST['submit'];
  45.  
  46.  
  47. #check if the user has input and store it in COMMENTS else echo out NOT INSERTED
  48. if( isset($submit) ) {
  49. $insert = @mysql_query("USE codb");
  50. $insert = @mysql_query("INSERT INTO comment (ip,name,comment) VALUES ('$ip','$name','$comment') ");
  51. echo '<span style="color:#000;background:rgba(30, 250, 30, 0.1);border:1px solid #0f0;">Inserted</span>';
  52. }else {
  53.     echo '<span style="color:#f00;background:rgba(250, 10, 10, 0.3);border:1px solid #f00;">Please fill out all the fields correctly</span>';
  54. }
  55.  
  56. ?>
  57.  
  58.  
  59. <!--   PREVIEW COMMENTS   -->
  60.  
  61.  
  62.  
  63. <?php
  64. include('connect.php');     #connect CODB
  65.         #Assign variables
  66. $s = date("d/m/y h:i:s");    #Assign the date of input
  67. $getquery = mysql_query("SELECT * FROM comment ORDER BY id DESC LIMIT 70")or die(mysql_error());     #get comments
  68.  
  69.  
  70.  
  71. #Check if there are comments and preview them
  72.  
  73.  
  74. while ($rows = mysql_fetch_assoc($getquery))  {
  75.     $id = $rows['id'];
  76.     $s = $rows['submission_date'];
  77.     $name = $rows [ 'name' ];
  78.     $comm = $rows ['comment'];
  79.  
  80.  
  81.     echo "<br/>$id . <h3 style=\"font-size:25px;\">$name</h3>";
  82.     echo "<i>$s<br/><br/></i>";
  83.     echo "$comm<br/><br /><hr/>";
  84. }
  85.  
  86.  
  87. ?>
  88.  
Jan 31 '16 #8
Rabbit
12,516 Expert Mod 8TB
I don't see any reason why the comment would keep inserting unless the user is constantly refreshing the page and resubmitting the data.
Feb 1 '16 #9
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??? tnx
Feb 1 '16 #10
And I've also tried the
Expand|Select|Wrap|Line Numbers
  1. INSERT IGNORE ...
and
Expand|Select|Wrap|Line Numbers
  1. ON DUPLICATE KEY
but no success (the
Expand|Select|Wrap|Line Numbers
  1. ON DUPLICATE KEY
doesn't even insert the comments in the first place.
May 3 '16 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: RSG | last post by:
Hi, Stupid question: how do I get an XSLT stylesheet to emit a comment into the HTML output file? Obviously this won't work; it's interpreted as a comment in the stylesheet: <template ...>...
2
by: Raffi | last post by:
Here's my HTML code. What I'm trying to do is when the button is pushed to refresh the popup window information, I want the popup to return to the front. The way my code is now, when refreshed the...
1
by: Patrick Delifer | last post by:
Is there a way to not let a page scroll back to the top if the user has scrolled down and the page is refreshed? Users are selecting Datagrid items and they are always brought back to the top when...
3
by: Vangelis | last post by:
Hi, I'm currently successfully retrieving the list of computers connected on the differents domains of our network via the System.DirectoryServices.DirectoryEntry class. What I'd like to have...
10
by: Rob Nicholson | last post by:
In our application, we've added a bit of JavaScript that updates a title as the user types into a textbox. To trigger this, we patch into the "onkeyup" and "onpaste" events: ...
6
by: frizzle | last post by:
Hi there I've built this user management system, using PHP & mySQL, to manage users that can comment on a certain site. Users have to be logged in to comment. Below each comment is (how...
0
by: Milkstr | last post by:
I have a database set where users predict the scores of football matches, i want to be able to display each users selection using just 2 pages, first page to select the username the second to display...
0
by: SIXFACESANKAR | last post by:
Hi, In my application, once the user logs in code is written in session_onstart to update / insert the user status . Also there is code written in session_onend to update the user status again....
14
by: Siv | last post by:
Hi, Just busily coding away and removed a procedure from my code and all of a sudden an error came up miles away from the location of the piece of code I removed and it relates to the XML...
39
by: polas | last post by:
Afternoon all. I was just wondering about this point - I have (generally) used // for commenting a single line in C, but from looking at code other people have written it seems many use /* */...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.