Jump to content

Error: Submitting Form Multiple Times


unsider

Recommended Posts

I am running Safari on OS X, and I have designed a simple little comment page, with the basic variables, $date, $text, $session_username, etc...

 

Well when the page is reloaded, the form is submitted twice, and this is the problem.

 

How would I go about fixing this error, so that the user an reload the page without the form being submitted twice?

 

If you needs samples of my code, just let me know.

Link to comment
https://forums.phpfreaks.com/topic/92745-error-submitting-form-multiple-times/
Share on other sites

This bit of code, allows the user to input the information into the DB, then it outputs what they have added.

When the page is reloaded, the data is then displayed a second time.

I've discovered if you add a question mark to the end before the reload it does not resend the form again.

 

http://example.com/index.php?

 

		
	if (!@mysql_select_db("//working database")) {
		echo 'Unable to locate the ' . 'database.';
}

	if(isset($_POST['commenttext'])) {
		$commenttext = $_POST['commenttext'];
		$name = $_POST['name'];
		$email = $_POST['email'];

	$sql = "INSERT INTO comments SET
		commenttext ='$commenttext',
		commentdate =NOW(),
		name ='$name',
		email='$email'";


	if (!@mysql_query($sql)) {
		echo 'Error adding query: ' . mysql_error();
}
}

		echo 'The comments listed in the database...<br>';

	$result = @mysql_query('SELECT commenttext, commentdate, name, email FROM comments');
		if (!$result) {
			echo 'Error performing query: ' . mysql_error();
}

echo '<table>';
$tr=1;
while ($row = mysql_fetch_array($result)) {
echo '<tr class="tr' . $tr . '"><td>' . $row["name"] . ' says: <br>' . $row['commentdate'] . '<br>' . $row['commenttext'] . '</td></tr>'; 

if($tr==1){
	$tr=2;
}
else if($tr==2){
	$tr=1;
}
}
echo '</table>';

echo '<br>';	

		echo '<a href="' . $_SERVER['PHP_SELF'] . '?addcomment=1">Add comment!</a>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.