Jump to content

[SOLVED] Form submits to database twice???


cmaclennan

Recommended Posts

I have a multi part form that submits portions of the data to 4 different tables however when submitted everything is entered into the databases fine expcept in one part where it adds it in twice. Any suggestions would be appreciated.

 

// Make the query.
	$query = "INSERT INTO customers (customer_id, company, contact, address, address2, city, state_prov, zip_postal, country, phone, email, fax, tax_id) VALUES ('', '$co', '$cn', '$ad' , '$ad2', '$ct', '$sp', '$zp', '$cou', '$ph', '$em', '$fx', '$tx')";
	$result = @mysql_query ($query); // Run the query.
	$customer_id = mysql_insert_id();

	$query = "INSERT INTO shipping (shipping_id, sh_company, sh_contact, sh_address, sh_address2, sh_city, sh_state_prov, sh_zip_postal, sh_country, sh_phone, sh_email, sh_fax, customer_id) VALUES ('', '$cos', '$cns', '$ads' , '$a2s', '$cts', '$sps', '$zps', '$cous', '$phs', '$ems', '$fxs', '$customer_id')";	
	$result = @mysql_query ($query); // Run the query.
	$shipping_id = mysql_insert_id();

	$query = "INSERT INTO orders (order_id, date, po, invoice_date, invoice, sent_mfg, req_date, final_date, shipped_via, tracking, shipping_id) VALUES ('', '$dt', '$po', '$idt' , '$in', '$mfg', '$re', '$fn', '$sh', '$tr', '$shipping_id')";
	$result = @mysql_query ($query); // Run the query.
	$order_id = mysql_insert_id();

	$result = @mysql_query ($query); // Run the query.
	foreach($_POST as $key => $value)
{
	//looping through all posted fields
	if(strpos($key, 'partid_') !== false)
	{
		//found a part field, need to find out the _x number, then insert the entire row
		$suffix = substr($key, -1); //this gets the _x number
		$partid = $_POST['partid_' . $suffix];
		$quantity = $_POST['quantity_' . $suffix];
		$desc = $_POST['desc_' . $suffix];
		$serial = $_POST['serial_' . $suffix];

		$query = "INSERT INTO parts_ordered (partid, quantity, `desc`, serial, order_id) VALUES ('$partid', '$quantity', '$desc', '$serial', '$order_id')";
		$result = mysql_query($query);
	}
}
	if ($result) { // If it ran OK.

Link to comment
https://forums.phpfreaks.com/topic/160972-solved-form-submits-to-database-twice/
Share on other sites

You're running that query twice.

 

$query = "INSERT INTO orders (order_id, date, po, invoice_date, invoice, sent_mfg, req_date, final_date, shipped_via, tracking, shipping_id) VALUES ('', '$dt', '$po', '$idt' , '$in', '$mfg', '$re', '$fn', '$sh', '$tr', '$shipping_id')";
      $result = @mysql_query ($query); // Run the query the first time.
      $order_id = mysql_insert_id();
      
      $result = @mysql_query ($query); // Run the query the second time.
      foreach($_POST as $key => $value)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.