...

View Full Version : problem with update with multiple textbox



che_anj
12-31-2007, 03:33 AM
hello anyone could help me..

I have like 4 text field and 1 button..

example:


echo '<form name="prod" method="post">';
$query="select * from products";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
echo '<input type="text" name="quantity" value="$row[quantity]">';
}
echo '<input type="submit" name="update" value="Update">';
</form>

if(isset($_POST['update']))
{
foreach(isset($_POST['qnty']))
{
mysql_query("update products set quantity='$_POST['qnty'] where ip='$ip'");

}
}


What i want to happen is , I want to update the input of quantity, if the value of the textbox(quantity) is 3 and im going to type 5 then it will update into what is being input in the quantity field. my problem is the last textbox will only be update.. since it has multiple number of textfield and there is only 1 submit button..

Anyone could help me this..

Thanks and happy new year...

oesxyl
12-31-2007, 03:54 AM
echo '<form name="prod" method="post">';
$query="select * from products";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
echo '<input type="text" name="quantity'.$row['ip'].'" value="'.$row[quantity].'">';
}
echo '<input type="submit" name="update" value="Update">';
</form>

if(isset($_POST['update'])) {
foreach($_POST as $key => $value) {
$ip = preg_replace("/quantity(\d+)/","$1",$key);
if($ip !== $key){
mysql_query('update products set quantity='.$value.' where ip='.$ip);
}
}
}



is not tested and I presume that field id from products table is integer.

nest regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum