0

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"];
}
			}
?>
Attachments dynamic_array.jpg 22.49 KB
2
Contributors
8
Replies
20
Views
6 Years
Discussion Span
Last Post by rpv_sen
0
<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>
0

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];
}
			}
?>
0

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);
		}
	}
?>
1

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);
Votes + Comments
thanks for sharing
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.