Hello pals. I have a code here that is updating only the last column of my sql database table. how can I upgrade it to work for the rest upper rows please. my code is as follows
<?php
error_reporting (0);
// Connect to server and select databse.
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "ison";
$con=mysql_connect("localhost", "root", "")or die("cannot connect");
mysql_select_db("ison",$con)or die("cannot select DB");
$result = mysql_query("SELECT * FROM customer");
?>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title>Pending Report</title>
</head>
<body>
<form method="post" action="#">
<table width="1200" border="1" cellspacing="1" cellpadding="0">
<tr>
<th>S.No</th><th>MSISDN</th><th>CUSTOMERNAME</th><th>TIME</th><th>COMPANY</th><th>REASON</th><th>CLOSED</th><th>COMMENT</th> <th>Update</th>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['S_NO']; ?></td>
<td><input name="MSISDN" type="text" id="MSISDN"value="<?php echo $rows['MSISDN']; ?>"/></td>
<td><input name="CUSTOMERNAME" type="text" id="CUSTOMERNAME"value="<?php echo $rows['CUSTOMERNAME']; ?>"/></td>
<td><input name="TIME" type="text" id="TIME"value="<?php echo $rows['TIME']; ?>"/></td>
<td><input name="COMPANY" type="text" id="COMPANY"value="<?php echo $rows['COMPANY']; ?>"/></td>
<td><input name="REASON" type="text" id="REASON"value="<?php echo $rows['REASON']; ?>"/></td>
<td><input name="CLOSED" type="checkbox" id="CLOSED"value=" <?php echo $rows['CLOSED']; ?> "checked />Closed</td>
<td><input name="COMMENT" type="text" id="COMMENT" value="<?php echo $rows['COMMENT']; ?>" size=""/>
</td>
<td><input type="submit" name="submit" value="update" />
</td></form>
<?php
if(isset($_POST["submit"]))
{
$MSISDN=$_POST['MSISDN'];
$CUSTOMERNAME=$_POST['CUSTOMERNAME'];
$TIME=$_POST['TIME'];
$COMPANY=$_POST['COMPANY'];
$REASON=$_POST['REASON'];
$CLOSED=$_POST['CLOSED'];
$COMMENT=$_POST['COMMENT'];
$query = "SELECT * FROM `customer` WHERE `MSISDN` = '$_POST[MSISDN]'";
$result = mysql_query($query);
$sql = array();
foreach($_POST as $field => $value) {
$sql[] = '("'.mysql_real_escape_string($row['S_NO']).'")';
}
$sql1="UPDATE customer SET COMMENT='$_POST[COMMENT]' WHERE MSISDN='$_POST[MSISDN]'";
$result=mysql_query($sql1);
header('Location: index.php');
echo '<span style="color:#6f892c;">RECORD INSERTED SUCCESSFULLY...</span>';
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else
{ header('Location: index.php');
echo '<span style="color:#6f892c;">RECORD INSERTED SUCCESSFULLY....</span>';
}
}
}
?>
</table>
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "20";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
</head>
<body>
<?php
echo "Page is refreshing...!";
?>
</body></html>