Hi Friends

i have some problem in update my dynamic text box value for particular id alone,

i want to update only the 2 column fields into my database,

i have used the below code. i am not able update the fields into my DB. Please help me to solve this issue.

<?php

			$bp_approve_qty = $_POST["bp_approve_qty"];
			$bp_approve_rate = $_POST["bp_approve_rate"];
			$id = $_POST["id"];
			$limit = count($bp_approve_qty);
			//echo $limit;
			
			for($i=0;$i<$limit;$i++) {
			$bp_approve_qty[$i] = mysql_real_escape_string($bp_approve_qty[$i]);
			$bp_approve_rate[$i] = mysql_real_escape_string($bp_approve_rate[$i]);
				
if($_POST['submit']=="Submit")
{
	$query = "Update material_indent_req set bp_approve_qty='".$bp_approve_qty."', bp_approve_rate='".$bp_approve_rate."' where id=".$id;
	echo $query;
	mysql_db_query($database,$q);
	$change=$_POST["id"];
}
			}
?>

Post your html form...

<tr class="light">
    <td height="30" align="center"><?php echo $i;?></td>
    <td align="center"><input name="mat_code[]" type="text" class="inputlinerate" id="mat_code[]" value="<?php echo $inm['mat_code'];?>" readonly="readonly" /><input type="text" name="id[]" id="id[]" class="inputlinerate" value="<?php echo $inm['id']?>" /></td>
    <td><input name="sub_mat_name[]" type="text" class="inputlinem" id="sub_mat_name[]" value="<?php echo $inm['sub_mat_name'];?>" readonly="readonly" /></td>
    <td align="center"><input name="sub_mat_unit[]" type="text" class="inputlinel" id="sub_mat_unit[]" value="<?php echo $inm['sub_mat_unit']; ?>" readonly="readonly"  /></td>
    <td align="center"><input name="stock_at_site[]" type="text" class="inputlinel" id="stock_at_site[]" value="<?php echo $com['sum(stock_at_site)']?>" readonly="readonly" /></td>
    <td align="center"><input name="required_qty[]" type="text" class="inputlinel" id="required_qty[]" value="<?php echo $com['sum(required_qty)'];?>" readonly="readonly" /></td>
    <td align="center"><input name="required_date[]" type="text" class="inputlinel" id="required_date[]" value="<?php echo $inm['required_date'];?>" readonly="readonly" /></td>
    <td><input type="text" class="inputlinerate" name="bp_approve_qty[]" id="bp_approve_qty[]" /></td>
    <td><input type="text" class="inputlinerate" name="bp_approve_rate[]" id="bp_approve_qty[]" /></td>
  </tr><?php $i++; } ?>
  <tr class="light">
    <td height="30" colspan="9" align="center"><input type="submit" name="submit" value="Submit" /></td>
  </tr>

Hi

I have changed the code and its display is working fine, but unable to update it in DB
my code is

<?php

			$bp_approve_qty = $_POST["bp_approve_qty"];
			$bp_approve_rate = $_POST["bp_approve_rate"];
			$limit = count($bp_approve_qty);
			//echo $limit;
			
			for($i=0;$i<$limit;$i++) {
			$bp_approve_qty[$i] = mysql_real_escape_string($bp_approve_qty[$i]);
			$bp_approve_rate[$i] = mysql_real_escape_string($bp_approve_rate[$i]);
				
if($_POST['submit']=="Submit")
{
	$query = "Update material_indent_req set bp_approve_qty='".$bp_approve_qty[$i]."', bp_approve_rate='".$bp_approve_rate[$i]."' where id='".$_POST['id'][$i]."'";
	echo $query;
	mysql_db_query($database,$q);
	$change=$_POST["id"][$i];
}
			}
?>

Test this... Before testing take the backup of your table..

<?php
	extract($_POST);
	$limit = count($bp_approve_qty);
	if($submit)
	{
		for($i=0;$i<$limit;$i++) 
		{
			$qty = mysql_real_escape_string($bp_approve_qty[$i]);
			$rate = mysql_real_escape_string($bp_approve_rate[$i]);
			$update_id = mysql_real_escape_string($id[$i]);
			$query = "Update material_indent_req set bp_approve_qty='".$qty."', bp_approve_rate='".$rate."' where id=".$update_id;
			//echo $query;
			mysql_query($query);
		}
	}
?>

Hi

I got my mistake, and now i have solve the problem, and my mistake is

Old Code

$query = "Update material_indent_req set bp_approve_qty='".$bp_approve_qty[$i]."', bp_approve_rate='".$bp_approve_rate[$i]."' where id='".$_POST['id'][$i]."'";
echo $query;
mysql_db_query($database,$q);

New Code

$query = "Update material_indent_req set bp_approve_qty='".$bp_approve_qty[$i]."', bp_approve_rate='".$bp_approve_rate[$i]."' where id='".$_POST['id'][$i]."'";
echo $query;
mysql_db_query($database,$query);
commented: thanks for sharing +5

Thanks for your post karthik

ok fine.. mark as solved

i will mark it as you wish

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.