as you see in this code i made a table by selecting models from table in my database.. however i posted the return of the select query to be like the primary column for this table and put it into the while loop so it keeps generating rows till the models which came with the select query be finished now i got a a problem when i'm trying to get this models in a $_Post[''] supergloble it keeps send me only the last value it gets from the loop my question is how to get each and every value from the this loop to use it in a single insert query in my DB?
and sorry for the bad English :S !!
<form class="form-signin" action="<?php $_SERVER['PHP_SELF'];?>" method="Post">
<?php
$models = mysql_query("SELECT `Model_Name` FROM `models` WHERE `Brand` = 20");
while($row = mysql_fetch_array($models))
{
echo '
<tr>
<td><input type="text" name="mode[]" value="'.$row['Model_Name'].'"></td>
<td><input type="text" name="sellout[]" value=""></td>
<td><input type="text" name="shelfshare[]" value=""></td>
<td><input type="text" name="price[]" value=""></td>
<td><input type="text" name="Shortage[]" value=""></td>
<td><input type="text" name="Inventory[]" value=""></td>
</tr>
';
}
?>
</form>
the inserting script
$date = date("Y-m-d");
foreach($_POST['mode'] as $key => $mode){
$sellout = $_POST['sellout'][$key];
$shelfshare = $_POST['shelfshare'][$key];
$price = $_POST['price'][$key];
$shortage = $_POST['shortage'][$key];
$inventory = $_POST['inventory'][$key];
mysql_query("INSERT INTO `smartdailyreport`(`SFO_Code`, `Model`, `Sell_Out`, `Shelf_Share`, `Price`, `Shortage`, `Inventory`, `Date`) VALUES ('".mysql_real_escape_string($_SESSION['idd'])."','".mysql_real_escape_string($mode)."','".mysql_real_escape_string($sellout)."','".mysql_real_escape_string($shelfshare)."','".mysql_real_escape_string($price)."','".mysql_real_escape_string($shortage)."','".mysql_real_escape_string($inventory)."','".mysql_real_escape_string($date)."')") or die(mysql_error());
}
$POSTmight throw an error for undefined variable - better fix it:$_POSTforeachloop, otherwise you're just overwriting your values each time it iteratesmysql_queryis also being removed from PHP in future versions because it's so easy to abuse like this. PDO is not hard to learn and makes it easier to write properly escaped queries.