User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,600 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,443 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1582 | Replies: 2
Reply
Join Date: Sep 2007
Location: uk
Posts: 17
Reputation: searchacar is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
searchacar searchacar is offline Offline
Newbie Poster

Solution How to avoid duplicate entries on refresh

  #1  
Sep 9th, 2007
Hi,
I have one issue on entering data into database twice. When user add some details on my website's form pages and click on submit then data is added correctly. But if someone hit refresh button again then it will add another duplicate entry.
Is there something in php i can do to avoid duplicate form entries. thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2007
Location: Sofia, Bulgaria
Posts: 138
Reputation: MitkOK is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
MitkOK's Avatar
MitkOK MitkOK is offline Offline
Junior Poster

Re: How to avoid duplicate entries on refresh

  #2  
Sep 9th, 2007
Hi.

You can set mysql fileds as "unique" and check if values exists in DB before inserting.


- Mitko Kostov
Reply With Quote  
Join Date: Aug 2007
Location: Morrisdale, PA
Posts: 52
Reputation: JeniF is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
JeniF's Avatar
JeniF JeniF is offline Offline
Junior Poster in Training

Solution Re: How to avoid duplicate entries on refresh

  #3  
Sep 9th, 2007
You can set a session for this as well. Within the headtags place code to start and register the session:

<?php
session_start();
if (!session_is_registered("nextValidSubmission")) {
session_register("nextValidSubmission");
}
if (isset($_POST['emailAddress']) && $_POST['submissionId'] == $_SESSION['nextValidSubmission']) {
}
$_SESSION['nextValidSubmission'] = rand(1000000,9999999);
?>

Then within your form, place a hidden field:

<input type="hidden" value="<?php echo $_SESSION['nextValidSubmission'];?>" name="submissionId">


I keep hitting "escape", but I'm still here!!!!
:}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 7:01 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC