This code is not getting values when I press update.
Its showing the values from Db in fields.
But at the time of update whrere I SET Values it gets null values.
I am using name of input as acmake[]
and then using for loop but its not working.
<strong>Update multiple rows in mysql</strong><br>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="onm"; // Database name
$tbl_name="sims_ac"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$a='S-KTR-0139';
$sql="SELECT * FROM $tbl_name WHERE SiteID ='$a'";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>SiteId</strong></td>
<td align="center"><strong>AcMake</strong></td>
<td align="center"><strong>AcCapacity </strong></td>
<td align="center"><strong>AMP</strong></td>
<td align="center"><strong>qty</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $SiteId[]=$a; ?><? echo $a; ?></td>
<td align="center"><input name="AcMake[]" type="text" id="AcMake" value="<? echo $rows['AcMake']; ?>"></td>
<td align="center"><input name="AcCapacity[]" type="text" id="AcCapacity" value="<? echo $rows['AcCapacity']; ?>"></td>
<td align="center"><input name="AMP[]" type="text" id="AMP" value="<? echo $rows['AMP']; ?>"></td>
<td align="center"><input name="qty[]" type="text" id="qty" value="<? echo $rows['qty']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($_POST["Submit"]=="Submit")
{
for($i=0;$i<$count;$i++){
echo "hi";
$sql1="UPDATE $tbl_name SET AcMake='$AcMake[$i]', AcCapacity='$AcCapacity[$i]', AMP='$AMP[$i]', qty='$qty[$i]' WHERE SiteId='$a'";
$result1=mysql_query($sql1);
}
}
if($result1){
header("location:um.php");
}
mysql_close();
?>