我有一个 php 表单来更新 MySQL 表。提取工作完美,但更新不起作用。这是我的表单代码:
<?php
$sql= "SELECT client.resID AS resID, client.resName AS resName FROM client WHERE client.resID =".$_GET["resID"];
$rs = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
$sqlM= "SELECT menu.id AS mid, menu.name AS mname FROM menu WHERE menu.resID =".$_GET["resID"];
$rsM = mysql_query($sqlM) or die($sqlM."<br/><br/>".mysql_error());
$sqlF= "SELECT facilities.id AS fid, facilities.name AS fname FROM facilities WHERE facilities.resID =".$_GET["resID"];
$rsF = mysql_query($sqlF) or die($sqlF."<br/><br/>".mysql_error());
$sqlS= "SELECT services.id AS sid, services.name AS sname FROM services WHERE services.resID =".$_GET["resID"];
$rsS = mysql_query($sqlS) or die($sqlS."<br/><br/>".mysql_error());
// $names array now contains all names
$i = 0;
echo '<table width="50%">';
echo '<tr>';
echo '<td>ID</td>';
echo '<td>Name</td>';
echo '<td>Edit</td>';
echo '</tr>';
echo "<form name='form_update' method='post' action='client_admin_post.php'>\n";
while ($fm = mysql_fetch_array($rsM)) { // loop as long as there are more results
$mnames[] = $fm['mname'];
$mid[] = $fm['mid']; // push to the array
echo '<tr>';
echo "<td>Menu :</td>";
echo "<td><input type='text' size='40' name='mname' value='{$fm['mname']}' /></td>";
echo "<td>{$fm['id']}<input type='hidden' name='mid' value='{$fm['mid']}' /></td>";
echo '</tr>';
++$i;
print_r($mnames);
}
while ($ff = mysql_fetch_array($rsF)) { // loop as long as there are more results
$fnames[] = $ff['fname'];
$fid[] = $ff['fid']; // push to the array
echo '<tr>';
echo "<td>Facilities :</td>";
echo "<td><input type='text' size='40' name='fname' value='{$ff['fname']}' /></td>";
echo "<td>{$ff['id']}<input type='hidden' name='fid' value='{$ff['fid']}' /></td>";
echo '</tr>';
++$i;
}
while ($fs = mysql_fetch_array($rsS)) { // loop as long as there are more results
$snames[] = $fs['sname'];
$sid[] = $fs['sid']; // push to the array
echo '<tr>';
echo "<td>Services :</td>";
echo "<td><input type='text' size='40' name='sname' value='{$fs['sname']}' /></td>";
echo "<td>{$fs['id']}<input type='hidden' name='sid' value='{$fs['sid']}' /></td>";
echo '</tr>';
++$i;
}
echo'<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>';
?>
这是我的邮政编码:
$size = count($_POST['mname']);
$i = 0;
while ($i < $size) {
$mname= $_POST['mname'][$i];
$mid = $_POST['mid'][$i];
$query = "UPDATE menu SET name = '$mname' WHERE id = '$mid' LIMIT 1";
mysql_query($query) or die ("Error in query: $query");
echo "$mname<br /><br /><em>Updated!</em><br /><br />";
++$i;
}
$size = count($_POST['fname']);
$i = 0;
while ($i < $size) {
$fname= $_POST['fname'][$i];
$fid = $_POST['fid'][$i];
$query1 = "UPDATE facilities SET name = '$fname' WHERE id = '$fid' LIMIT 1";
mysql_query($query1) or die ("Error in query: $query1");
echo "$fname<br /><br /><em>Updated!</em><br /><br />";
++$i;
}
$size = count($_POST['sname']);
$i = 0;
while ($i < $size) {
$sname= $_POST['sname'][$i];
$sid = $_POST['sid'][$i];
$query3 = "UPDATE services SET name = '$sname' WHERE id = '$sid' LIMIT 1";
mysql_query($query3) or die ("Error in query: $query3");
echo "$sname<br /><br /><em>Updated!</em><br /><br />";
++$i;
}
我在帖子页面中获得了“更新”状态,但 MySQL 表中没有任何更新。如何解决这个问题呢?非常感谢您的帮助:D