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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.