0
<form id="form1" name="form1" method="post" action="updatebodyNo.php">

<table width="356" border="0" align="center">
  <tr>
    <td width="94"><span class="style12"><span class="style12 style57">BodyNo</span></span></td>
    <td width="155"><span class="style12"><span class="style12 style57">Defect Code</span></span></td>
    <td width="93"><span class="style12"><span class="style12 style57">Quantity</span></span></td>
  </tr>
  <tr>
  	
	<?php 
	include ("connection.php");
	// get value of id that sent from address bar
	$bodyNo=$_GET['bodyNo'];
	$sq1 = mysql_query ("SELECT * FROM paintshop WHERE bodyNo = '$bodyNo'") or die ("error");
	while($result = mysql_fetch_array($sq1)){
	?>
    <td><span class="style12 style57">
      <input type="text" name="bodyNo[]" id="bodyNo[]" value="<?php echo $result['bodyNo']; ?>"/>
    </span></td>
    <td><span class="style12"><span class="style12 style57">
      <input type="text" name="defect_code[]" id="defect_code[]" value="<?php echo $result['defect_code']; ?>"/>
    </span></span></td>
    <td><input type="text" name="qty[]" id="qty[]" value="<?php echo $result['qty']; ?>"/></td>
  </tr><?php } ?>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit" />
      <input type="reset" name="Reset" value="Reset" /></td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>

THEN updatebodyNo.php code

<?php
include("connection.php");
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("paintshop", $con);


$bodyNo = $_POST['bodyNo'];
$defect_code = $_POST['defect_code'];
$qty = $_POST['qty'];
//$EndDate = $_POST['EndDate'];

$limit = count($bodyNo);

for($i=0;$i<$limit;$i++) {
    $bodyNo[$i] = mysql_real_escape_string($bodyNo[$i]);
    $defect_code[$i] = mysql_real_escape_string($defect_code[$i]);
    $qty[$i] = mysql_real_escape_string($qty[$i]);
    //$EndDate[$i] = mysql_real_escape_string($EndDate[$i]);

    $query = "UPDATE paintshop SET bodyNo='$bodyNo[$i]', defect_code='$defect_code[$i]', qty='$qty[$i]' WHERE bodyNo='$bodyNo[$i]'";	
	
		$result = mysql_query($query);
//memaparkan mesej sama ada berjaya atau tidak
if ($query==TRUE) 
echo "<script type = 'text/javascript'> alert (' SUCCSESFUL INSERTED!'); </script>";
echo "<script>window.location = 'userView1.php?';</script>";
if ($query==FALSE)
echo "<script type = 'text/javascript'> alert (' ENCOUNTERED AN ERROR!'); </script>";
echo "<script>window.location = 'userView1.php?';</script>";

}  

mysql_close($con)
?>

the problem is, when i update, all information become same.

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by urtrivedi
0

Problem is in your primary key.
I guess you want to update all item related to say body number 1 at the same time.

But you must also need one key to identify row in the table paint shop.

So your update statement is using only one where condition. You must add one more condition to identify the specific row update.


Also I would suggest not to allow updating primary key of table.

If you are still not clear, post your paintshop table definition (sql) here.

Edited by urtrivedi: n/a

This topic has been dead for over six months. 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.