提交后数据库未更新。我什至没有收到错误。在这里,我试图从数据库中检索值并以 HTML 表格格式显示,用户也可以从这里更新值。因此,当我在这里更改值并提交时,数据库没有得到更新。
<?php
print"<center><h3><a href=\"index.html\">Go Back</a></h3><br>";
// Connect to server and select databse.
$con = mysql_connect('localhost','tpsadmin','tps')or die("Cannot connect to DB");
mysql_select_db('traffic',$con)or die("Cannot select DB");
$query = "SELECT * FROM emergency";
$result = mysql_query($query) or die(mysql_error());
// Count table rows
$count=mysql_num_rows($result);
//UPDATE `emergency` SET `t_sigid` = '2',`e_priority` = '3' WHERE `emergency`.`e_jid` =70;
if( isset($_POST['Submit'])){
for($i=0;$i<$count;$i++){
$sql1 = "UPDATE emergency SET
e_latitude='{$_POST['e_latitude'][$i]}',
e_longitude='{$_POST['e_longitude'][$i]}',
t_sigid='{$_POST['t_sigid'][$i]}',
e_priority='{$_POST['e_priority'][$i]}'
WHERE e_jid='$id[$i]'";
$result1 = mysql_query($sql1) or die(mysql_error());
}
}
if($result1){
header("location: em_disp.php");
}
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script language="JavaScript1.1" type="text/javascript">
<!--
function mm_jumpmenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<title>Emergency Table - Update</title>
</head>
<body>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table border="5" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#808080" width="50%" text-align="center" id="AutoNumber2" bgcolor="#C0C0C0">
<tr>
<td align="center">e_jid</td>
<td align="center">amb_id</td>
<td align="center">e_latitude</td>
<td align="center">e_longitude</td>
<td align="center">t_sigid</td>
<td align="center">e_priority</td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="left"><?php $id[]=$rows['e_jid']; ?><?php echo $rows['e_jid']; ?></td>
<td align="center"><?php echo $rows['amb_id']; ?></td>
<td align="center"><input name="e_latitude[]" type="text" id="e_latitude" value="<?php echo $rows['e_latitude']; ?>" size="10"></td>
<td align="center"><input name="e_longitude[]" type="text" id="e_longitude" value="<?php echo $rows['e_longitude']; ?>" size="10"></td>
<td align="center"><input name="t_sigid[]" type="text" id="t_sigid" value="<?php echo $rows['t_sigid']; ?>" size="10"></td>
<td align="center"><input name="e_priority[]" type="text" id="e_priority" value="<?php echo $rows['e_priority']; ?>" size="10" /></td>
</tr>
<?php
}
?>
<tr>
<td colspan="6" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
</body>
</html>
请有人帮助我。谢谢 !