473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Repeating comment when refreshed

57 New Member
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 2296
zmbd
5,501 Recognized Expert Moderator Expert
Have you checked the code that is being ran on the page-load?
Nov 29 '15 #2
Toxicous8
57 New Member
YES!Over and over again.But I don't see anything suspicious.
Dec 2 '15 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Well, it's a little hard for us to say what's wrong without any code to look at.
Dec 2 '15 #4
Toxicous8
57 New Member
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 Recognized Expert Moderator MVP
How come you're inserting into table comment but reading from table comment4?
Dec 24 '15 #6
Toxicous8
57 New Member
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
Toxicous8
57 New Member
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 Recognized Expert Moderator MVP
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
Toxicous8
57 New Member
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

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

Similar topics

1
4706
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
1770
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 popup stays in the background confusing the users. Thanks for your help. --------HTML Code------ <html> <head> <script language="javascript"...
1
2580
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 I refresh the page...
3
391
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 in addition of the computers name is their comment (just like when you browse over your network places on XP). The only way I found is querying...
10
1898
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: FirstName.Attributes("onkeyup") = "ChangeTitle();" FirstName.Attributes("onpaste") = "ChangeTitle();" This works a treat but neither of these events fire if the user...
6
1572
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 original) the date of commenting, and the author. If the user changes his name in his profile, it changes everywhere. So what i mean is that the user_id...
0
1086
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 the info. The first page i've set so it just lists the different users that are in the database, using a repeating region. when someone clicks on...
0
1291
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. When the user logs in , session_onstart code is working correctly . But when the user either logs off / close the application window , there is...
14
3055
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 comment inserted at the top of the procedure. I had this happen once before and I couldn't fathom why it was complaining, the XML comment is like this:
39
2841
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 /* */ (which I only use if my comment will be over multiple lines) - does one way have any advantages over the other, or is the style exactly that, a...
0
7520
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6041
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.