Jump to content

why are duplicate records being made?


Evanthes

Recommended Posts

Im using this file to insert records into my database and for some reason it makes 2 for the same record each time its inserted. could someone please take a look and let me know what i might be doing wrong? thanks!
[code=php:0]

<?
include('include.php'); // include file
include 'opendb.php'; // includes mysql  connection


$name=$_REQUEST['name'];
$id=$_REQUEST['id'];
$contact=$_REQUEST['contact'];
$info=$_REQUEST['info'];
$date=$_REQUEST['date'];
$probable=$_REQUEST['probable'];
$query= "insert into prospects values (null, '".$name."', '".$contact."', '".$info."', '".$date."', '".$probable."')";
$result = mysql_query($query);
if ($result)
echo "<center>";
{echo mysql_affected_rows(). ' Record(s) updated.';}
echo "</center>";
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/27120-why-are-duplicate-records-being-made/
Share on other sites

[code=php:0]$query= "INSERT INTO `prospects` VALUES (NULL, '.$name.', '.$contact.', '.$info.', NOW(), '1')  LIMIT 1";
[/code]

great idea, i think that will solve my problem, although for some reason it wont work when i put the limit in. any ideas why?
thanks
at home i wrote 2 small functions
is_pageReSubmit($uniqueID) // returns true if user pressed refresh and false, if first time loading.
and PageSubmit($uniqueID); // sets a flag unique to the page that is_pageReSubmit() uses.

the code would look something like this:

[code]
if(is_pageReSubmit($uniqueID)){

  // perform insert

  // if insert is success then:
  PageSubmit($uniqueID);
}else{
  echo "Data already sent";
}
[/code]

The unique code i use to make a page unique is simply a hidden entry in the form.
I usually use md5(date());
Make sure this value is passed somehow into $_GET (preferably $_POST).
It is what you pass in as $uniqueID and voila!, a page that only runs it's data once.

PageSubmit() has to add the $uniqueID to a rolling array of say... size 20.
is_pageReSubmit() needs to poll the array and only return false if the $uniqueID wasn't found.

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.