I'm trying to update multple queries but the update is not working.
here is the code....
if (isset($_POST['btnSub']))
{
// Preset counter $p and switch $sw to 0
$p=$sw=0;
// Create UPDATE queries
foreach($_POST["entry"] as $data)
{
$sql[$p]="UPDATE major SET ";
foreach($data as $key => $value)
{
// Save first $key => $value pair for WHERE clause
if($sw==0){$w=$key."='".$value."'";$sw=1;}
// Setup fields to update
$sql[$p].=$key."='".$value."',";
}
// Remove last comma from query
$sql[$p]=substr($sql[$p],0,strlen($sql[$p])-1);
// Add WHERE clause to query
$sql[$p].=" WHERE ".$w;
// Reset switch and increment counter for next query
$sw=0;
$p++;
}
// Setup counter to execute queries
$p=0;
// Loop through UPDATE queries
while($p<count($sql))
{
mysql_query($sql[$p]) or die(mysql_error());
$p++;
}
}
// Setup query to fetch data from database table
$sql = "SELECT place,team,wl,gb,pcage,rs,ra,ags FROM major";
$results=mysql_query($sql) or die(mysql_error());
?>
<!-- Create form and populate table -->
<form action="#" method="POST">
<table>
<?php
$p=0;
while($row=mysql_fetch_array($results))
{
echo '<tr>
<td><input name="entry['.$p.'][place]" type="text" value="'.$row["place"].'"/></td>
<td><input name="entry['.$p.'][team]" type="text" value="'.$row["team"].'"/></td>
<td><input name="entry['.$p.'][wl]" type="text" value="'.$row["wl"].'"/></td>
<td><input name="entry['.$p.'][gb]" type="text" value="'.$row["gb"].'"/></td>
<td><input name="entry['.$p.'][pcage]" type="text" value="'.$row["pcage"].'"/></td>
<td><input name="entry['.$p.'][rs]" type="text" value="'.$row["rs"].'"/></td>
<td><input name="entry['.$p.'][ra]" type="text" value="'.$row["ra"].'"/></td>
<td><input name="entry['.$p.'][ags]" type="text" value="'.$row["ags"].'"/></td>
</tr>';
$p++;
}
?>
<tr>
<!-- Submit form to update database table. -->
<td colspan=8><input type="submit" name="btnSub" value="Submit"></td>
</tr>
</table>
The query shows but i need to update it.