Form is resubmitting

hi

all

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

$n1=$_POST[‘s_no’];
$n2=$_POST[‘contact_name’];
$n3=$_POST[‘phno’];
$n4=$_POST[‘email’];
$n5=$_POST[‘vehicle’];
$n6=$_POST[‘package’];
//$n6=substr($n6,0,6) ;

$n7=$_POST[‘reqdate’];
$n8=$_POST[‘time’];
$n8=str_pad($n8, 2, ‘0’, STR_PAD_LEFT).‘:00’;
$load_type=$_POST[‘load_type’];
$n9=$_POST[‘weight’];
$n10=$_POST[‘pickup_addr’];
$n11=$_POST[‘landmark’];
$n12=$_POST[‘drop_addr’];
$n13=$_POST[‘circle_name’];
$n14=$_POST[‘booking_id’];
$n15=$_POST[‘status’];
$n16=$_POST[‘remarks’];
$n17=$_POST[‘created_by’];
$n18=$_POST[‘created_on’];
$n19=$_POST[‘updated_by’];
$n20=$_POST[‘updated_on’];
$n21=$_POST[‘alt_phno’];

$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 ?>’)
</script>

please help me out

Thanks & regards

MD.Samiuddin

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.