Jump to content

Insert multiple entries into multiple tables


rondog

Recommended Posts

I have a form where a user can duplicate part of a form like below:

postq.jpg

 

I've named the fields with the HTML arrays (ie. "fieldName[]") and came up with this:

	//--> CONTROLLERS
	$system_controllers_qty			= $_POST['system_controllers_qty'];
	$system_controllers_make		= $_POST['system_controllers_make'];
	$system_controllers_model		= $_POST['system_controllers_model'];
	$system_controllers_serial_no	        = $_POST['system_controllers_serial_no'];
	for ($i = 0; $i < count($system_controllers_qty); $i++)
	{
		echo "qty " . clean($system_controllers_qty[$i]) . "<br/>";
		echo "make " . clean($system_controllers_make[$i]) . "<br/>";
		echo "model " . clean($system_controllers_model[$i]) . "<br/>";
		echo "serial_no " . clean($system_controllers_serial_no[$i]) . "<br/>";
	}

	//--> CPUS
	$system_cpus_qty			= $_POST['system_cpus_qty'];
	$system_cpus_model			= $_POST['system_cpus_model'];
	$system_cpus_serial_no			= $_POST['system_cpus_serial_no'];
	$system_cpus_speed			= $_POST['system_cpus_speed'];
	for ($i = 0; $i < count($system_cpus_qty); $i++)
	{
		echo "qty " . clean($system_cpus_qty[$i]) . "<br/>";
		echo "model " . clean($system_cpus_model[$i]) . "<br/>";
		echo "serial_no " . clean($system_cpus_serial_no[$i]) . "<br/>";
		echo "speed " . clean($system_cpus_speed[$i]) . "<br/>";
	}

	//--> DISKS
	$system_disks_qty			= $_POST['system_disks_qty'];
	$system_disks_make			= $_POST['system_disks_make'];
	$system_disks_model_no			= $_POST['system_disks_model_no'];
	$system_disks_size			= $_POST['system_disks_size'];
	$system_disks_serial_no			= $_POST['system_disks_serial_no'];
	for ($i = 0; $i < count($system_disks_qty); $i++)
	{
		echo "qty " . clean($system_disks_qty[$i]) . "<br/>";
		echo "make " . clean($system_disks_make[$i]) . "<br/>";
		echo "model_no " . clean($system_disks_model_no[$i]) . "<br/>";
		echo "size " . clean($system_disks_size[$i]) . "<br/>";
		echo "serial_no " . clean($system_disks_serial_no[$i]) . "<br/>";
	}

	//--> MEMORY
	$system_memory_qty			= $_POST['system_memory_qty'];
	$system_memory_serial_no		= $_POST['system_memory_serial_no'];
	$system_memory_manf			= $_POST['system_memory_manf'];
	$system_memory_part_no			= $_POST['system_memory_part_no'];
	$system_memory_size			= $_POST['system_memory_size'];
	for ($i = 0; $i < count($system_memory_qty); $i++)
	{
		echo "qty " . clean($system_memory_qty[$i]) . "<br/>";
		echo "serial " . clean($system_memory_serial_no[$i]) . "<br/>";
		echo "manf " . clean($system_memory_manf[$i]) . "<br/>";
		echo "part_no " . clean($system_memory_part_no[$i]) . "<br/>";
		echo "size " . clean($system_memory_size[$i]) . "<br/>";
	}

 

This just outputs all the fields I post at the moment. Say I have 3 different disk types, it's going to loop 3 times. Is it possible to make this all into 1 giant query or am I better off doing each query separately? Each section is a different table.

Link to comment
Share on other sites

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.