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.
10 2296 zmbd 5,501
Recognized Expert Moderator Expert
Have you checked the code that is being ran on the page-load?
YES!Over and over again.But I don't see anything suspicious.
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.
Okay then, here are the codes. - <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/>";
-
}
-
-
?>
-
Rabbit 12,516
Recognized Expert Moderator MVP
How come you're inserting into table comment but reading from table comment4?
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???
Hi again, i've updated the codes to the comment section but still repeating. The newer codes are - <!-- 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/>";
-
}
-
-
-
?>
-
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 ...>
...
|
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"...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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:
|
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...
|
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...
| |
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...
|
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. ...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |