Foreach two arrays help

If i do like this

$arrayObject1 = new ArrayObject($_POST['price']);
$arrayObject2 = new ArrayObject($_POST['weight']);
$iterator1 = $arrayObject1->getIterator();
$iterator2 = $arrayObject2->getIterator();
for ($iterator1->rewind(), $iterator2->rewind();
     $price = $iterator1->current(), $weight=$iterator2->current();
     $iterator1->next(), $iterator2->next())

mysql_query("insert into production(price, weight) values('".$price."', '".$weight."')") or sqlerr(__FILE__, __LINE__);

It Work - send to database (some_numbers of INSERTS with some_numbers of ID’s)

But i need only ONE insert (With ONE ID) , this data to the table.

Here is how it’s work before

		 $price1 = sqlesc($_POST['price1']);
		 $price2 = sqlesc($_POST['price2']);
		 $price3 = sqlesc($_POST['price3']);
		 $price4 = sqlesc($_POST['price4']);
		 $price5 = sqlesc($_POST['price5']);
		 $weight1 = sqlesc($_POST['weight1']);
		 $weight2 = sqlesc($_POST['weight2']);
		 $weight3 = sqlesc($_POST['weight3']);
		 $weight4 = sqlesc($_POST['weight4']);
		 $weight5 = sqlesc($_POST['weight5']);

and after i upgrate the html code

	<input size="7" name="weight1"> &#1075;&#1088;&#1072;&#1084;&#1084; <input size="7" name="price1"> &#1088;&#1091;&#1073;.
	<br />
	<input size="7" name="weight2"> &#1075;&#1088;&#1072;&#1084;&#1084; <input size="7" name="price2"> &#1088;&#1091;&#1073;.
	<br />
	<input size="7" name="weight3"> &#1075;&#1088;&#1072;&#1084;&#1084; <input size="7" name="price3"> &#1088;&#1091;&#1073;.
	<br />
	<input size="7" name="weight4"> &#1075;&#1088;&#1072;&#1084;&#1084; <input size="7" name="price4"> &#1088;&#1091;&#1073;.
	<br />
	<input size="7" name="weight5"> &#1075;&#1088;&#1072;&#1084;&#1084; <input size="7" name="price5"> &#1088;&#1091;&#1073;.
	</td>

to Jquery (with maximum 5 clones)

<div class="clone"><input size="7" name="weight[]"> &#1075;&#1088;&#1072;&#1084;&#1084; <input size="7" name="price[]"> &#1088;&#1091;&#1073;. - <a href="#" class="add" rel=".clone">Add more</a></div>

Now i need Upgrate New with Jquery to same (OLD INSERT) .

Thanks for help

Before you get any further, please be aware that the mysql_* extension is now deprecated as of the current version of PHP and will very likely be removed from the next 5.x version and will likely not be in PHP 6.x (when it eventually is released). You should migrate over to either the mysqli_* extension or to PDO. PDO is a better choice as it doesn’t tie you down so much to a particular database server software.

Once you have migrated you should use Prepared Statements to prevent SQL Injection attacks. Have a read of this article from the PHP manual, it shows how to use prepared statements with PDO and also explains the principle.

Thanks for information firstly. I will see how to work with PDO. But i still need help with my first post :slight_smile:

Both those form inputs will have the same array key when posted. You should be able to do a simple foreach() statement to get values.

<?php
foreach($_POST['price'] as $k => $price){
 $weight = $_POST['weight'][$k];

 //Query
}
?>