Form is resubmitting



I am submitting the form values to database. It is working fine. But sometimes the values are submitting multiple times

//$n6=substr($n6,0,6) ;

$n8=str_pad($n8, 2, ‘0’, STR_PAD_LEFT).‘:00’;

$sql=“INSERT INTO booking_details (s_no , contact_name , phno , email , vehicle , package , reqdate ,time , load_type , weight , pickup_addr , landmark , drop_addr , circle_name , booking_id , status , remarks , created_by , created_on , updated_by , updated_on,alt_phno) values (‘$num’,‘$n2’,‘$n3’,‘$n4’,‘$n5’,‘$n6’,‘$n7’,‘$n8’,‘$load_type’,‘$n9’,‘$n10’,‘$n11’,‘$n12’,‘$n13’,‘$name’,‘$n15’,‘$n16’,‘$n17’,‘$n18’,‘$n19’,‘$n20’,‘$n21’)”;

$result=mysql_query($sql) or die(mysql_error());

echo “<meta http-equiv=refresh content=\“0;URL=/$companyname/form.php\”>”;

<script language=“javascript”>
alert(‘<?= $mess,$name ?>’)

please help me out

Thanks & regards


Why are you sending a refresh on the result? That’s probably resubmitting the form in some browsers.

But then I see people sending header refreshes all the time now, and I really have to ask “for what?”

You could also prevent accidental form resubmits by adding a hash or ID number in a hidden input, stored in a DB on the server. Check against that to see if the form has already been submitted. The way I like to handle it is when I send the form, I add a record to my ‘validation’ table containing a unique ID, a timestamp, and the users IP addy. When they submit, I expire all timestamps > 20 minutes old, then check if that ID is in the ‘validation’ table. If so, delete it and then send the form data to the proper db. If it’s not in the table, I resend the form with everything plugged in just in case it took them that long to fill it out – so they don’t have to retype everything.