Jump to content

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.