Current location: Hot Scripts Forums » Programming Languages » PHP » php/mysql inserting twice into database with IE 6


php/mysql inserting twice into database with IE 6

Reply
  #1 (permalink)  
Old 04-22-04, 01:45 AM
sky4est sky4est is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Question php/mysql inserting twice into database with IE 6

For no good reason this code sometimes inserts the data twice into my mysql database. It seems to happen only from IE and XP and it seems to only happen randomly. Is it a POST or GET thing from the referring page? Any help would be great.
Thanks,
-Sky.

Here is my code:
PHP Code:

<?php

$connection
=mysql_pconnect("localhost","user","password");
if (!
$connection) {
 echo 
"Could not connect to MySQL server!";
 exit;
}


$db=mysql_select_db("database",$connection);
if (!
$db) {
 echo 
"Could not change into the database mondavi";
 exit;
}



$order_id $_REQUEST["order_id"];
$event_id $_REQUEST["event_id"];
$series_id $_REQUEST["series_id"];
$item_name $_REQUEST["item_name"];
$event_date $_REQUEST["event_date"];
$event_time $_REQUEST["event_time"];
$price_category $_REQUEST["price_category"];
$adult_tickets $_REQUEST["adult_tickets"];
$student_tickets $_REQUEST["student_tickets"];
$child_tickets $_REQUEST["child_tickets"];
$parking_permits $_REQUEST["parking_permits"];
$line_subtotal $_REQUEST["line_subtotal"];
$multiple_time_event_name_1 $_REQUEST["multiple_time_event_name_1"];
$multiple_time_event_date_time_1 $_REQUEST["multiple_time_event_date_time_1"];
$multiple_time_event_name_2 $_REQUEST["multiple_time_event_name_2"];
$multiple_time_event_date_time_2 $_REQUEST["multiple_time_event_date_time_2"];
$multiple_time_event_name_3 $_REQUEST["multiple_time_event_name_3"];
$multiple_time_event_date_time_3 $_REQUEST["multiple_time_event_date_time_3"];
$multiple_time_event_name_4 $_REQUEST["multiple_time_event_name_4"];
$multiple_time_event_date_time_4 $_REQUEST["multiple_time_event_date_time_4"];
$multiple_time_event_name_5 $_REQUEST["multiple_time_event_name_5"];
$multiple_time_event_date_time_5 $_REQUEST["multiple_time_event_date_time_5"];

?>


<?
$sql 
"INSERT INTO orders (order_id, event_id, series_id, item_name, event_date, event_time, price_category, adult_tickets, student_tickets, child_tickets, parking_permits, line_subtotal, multiple_time_event_name_1, multiple_time_event_date_time_1, multiple_time_event_name_2, multiple_time_event_date_time_2, multiple_time_event_name_3, multiple_time_event_date_time_3, multiple_time_event_name_4, multiple_time_event_date_time_4, multiple_time_event_name_5, multiple_time_event_date_time_5) VALUES ('$order_id', '$event_id', '$series_id', '$item_name', '$event_date', '$event_time', '$price_category', '$adult_tickets', '$student_tickets', '$child_tickets', '$parking_permits', '$line_subtotal', '$multiple_time_event_name_1', '$multiple_time_event_date_time_1', '$multiple_time_event_name_2', '$multiple_time_event_date_time_2', '$multiple_time_event_name_3', '$multiple_time_event_date_time_3', '$multiple_time_event_name_4', '$multiple_time_event_date_time_4', '$multiple_time_event_name_5', '$multiple_time_event_date_time_5')";

mysql_query($sql,$connection);
mysql_close($connection);


?>

Last edited by Nico; 12-10-07 at 10:23 AM.
Reply With Quote
  #2 (permalink)  
Old 04-22-04, 04:34 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
I think it's only a problem when a visitor double click the submit button, that's all !!
maybe you could have an anti-flood script to avoid this, another thing is to have a unique field in MySQL so the same order_id can't be inserted twice ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 04-22-04, 11:26 AM
sky4est sky4est is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
thanks

I have an auto increment 'id' field in my MySQL table, which is unique for each item ordered. At the moment it just moves on to the next value when it gets the double entry. How can I use it to allow only one insert to the database?

About the double submit, it's kinda hard to get away from because I use select lists to update the page and they submit the form when they update.....would moving the insert code into the same page and putting in a function help?

Last edited by sky4est; 04-22-04 at 11:33 AM.
Reply With Quote
  #4 (permalink)  
Old 04-22-04, 12:46 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

The purpose of auto_increment (at least the major part of it) is to allow inserting more than one records without worrying about duplicate (primary key) entries. So you don't want to try to limit that. If there is anything else that is unique across the data (e.g. SIN) then you can set this as primary key.

I am not sure what your form looks like but one thing I do sometimes is to refresh the page right after I do all the input check/processing (e.g. inserting into database). "Refreshing" I mean here is to use header('Location: '.$_SERVER['PHP_SELF'].'?action=thanks'); or something (could be REQUEST_URI instead of PHP_SELF, depending on what you are doing).

I can then place a confirmation handling message if ($_GET['action'] == 'thanks'). But this doesn't help sometimes, like when the user enters very sensitive info and you don't want to carry around in GET or SESSION.

My 33 cents.
__________________
Blavv =|
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
PHP/MySQL HELP URGENT mathieu67 PHP 1 04-13-04 03:46 PM
form not inserting information into the database sabret00the PHP 7 12-01-03 03:35 PM
Share database over the Internet nitinkedia New Members & Introductions 1 07-10-03 02:50 PM


All times are GMT -5. The time now is 10:28 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.