Evanthes Posted November 13, 2006 Share Posted November 13, 2006 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 fileinclude '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 More sharing options...
Orio Posted November 13, 2006 Share Posted November 13, 2006 You can use SQL's LIMIT:[code]$query= "insert into prospects values (null, '".$name."', '".$contact."', '".$info."', '".$date."', '".$probable."') LIMIT 1";[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/27120-why-are-duplicate-records-being-made/#findComment-123977 Share on other sites More sharing options...
Evanthes Posted November 13, 2006 Author Share Posted November 13, 2006 [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 Link to comment https://forums.phpfreaks.com/topic/27120-why-are-duplicate-records-being-made/#findComment-124079 Share on other sites More sharing options...
lead2gold Posted November 13, 2006 Share Posted November 13, 2006 that is semi dangerous code too the way you have it set up. anyone who continues to press refresh on that page will continue to generate inserts into the database. Link to comment https://forums.phpfreaks.com/topic/27120-why-are-duplicate-records-being-made/#findComment-124080 Share on other sites More sharing options...
Evanthes Posted November 13, 2006 Author Share Posted November 13, 2006 how could i change it differently? Link to comment https://forums.phpfreaks.com/topic/27120-why-are-duplicate-records-being-made/#findComment-124084 Share on other sites More sharing options...
lead2gold Posted November 13, 2006 Share Posted November 13, 2006 at home i wrote 2 small functionsis_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. Link to comment https://forums.phpfreaks.com/topic/27120-why-are-duplicate-records-being-made/#findComment-124087 Share on other sites More sharing options...
Evanthes Posted November 13, 2006 Author Share Posted November 13, 2006 i guess i dont understand, it tells me only 1 record was inserted yet 2 show up, think i might have a database problem or something? Link to comment https://forums.phpfreaks.com/topic/27120-why-are-duplicate-records-being-made/#findComment-124097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.