Jump to content

[SOLVED] Inserts data twice


peranha

Recommended Posts

I have the following code on a page, and this is inserting data twice to the sql database, and I cannot figure out why.  If I execute it in myadmin, it only inserts 1.

 

<?php

//  Create query and execute query.
$bquery = mysql_query("INSERT INTO " . $pregm . "positions (position_1, position_2, position_3) VALUES ('{$position1}', '{$position2}', '{$position3}')");

//  redirect back to the index page.
header ("Location: index.php");

exit();
?>

Link to comment
https://forums.phpfreaks.com/topic/134925-solved-inserts-data-twice/
Share on other sites

Are you sure that it's inserting it twice?

 

Positive it is

 

There is no reason the code you posted would insert twice. How are you calling the code? Is a page submitting to it?

 

I am calling if from a hyperlink.  That is the complete page, minus the database connection, and selecting the database.

Your browser is requesting the page twice. You need to add some logic to prevent the requests after the first one from executing the database query -

http://www.phpfreaks.com/forums/index.php/topic,226301.msg1043443.html#msg1043443

charset is set to utf-8

 

I will look into this.  Thanks.

 

Your browser is requesting the page twice. You need to add some logic to prevent the requests after the first one from executing the database query -

http://www.phpfreaks.com/forums/index.php/topic,226301.msg1043443.html#msg1043443

There are several reasons a page can get requested twice - browsers, url rewriting, javascript form submission...

 

The fix is to detect multiple page requests and ignore all but the first one.

 

The code in the first post is not even doing the minimum validation needed to prevent a search engine indexing the site from inserting empty records.

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.