0

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

3
Contributors
2
Replies
5
Views
10 Years
Discussion Span
Last Post by JeniF
0

Hi.

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


- Mitko Kostov

0

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"> 
:icon_eek:
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.