有人能告诉我我写错了吗?此代码显示来自数据库的数据,但是当我按下提交时,它只是重新加载页面并且数据库中没有这些字段的更新......我应该将更新查询中的变量更改为例如:$_POST['name']
<?php
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="db"; // Database name
$tbl_name="test"; // 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");
$sql="SELECT * FROM $tbl_name";
$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>Id</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>mid</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
$id[]=$rows['id'];
?>
<tr>
<td align="center">
<input name="id[]" type="text" id="id" value="<? echo $rows['id']; ?>">
</td>
<td align="center">
<input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>">
</td>
<td align="center">
<input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>">
</td>
<td align="center">
<input name="midmark[]" type="text" id="midmark" value="<? echo $rows['midmark']; ?>">
</td>
</tr>
<?
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
if(isset($_POST['submit'])){
for($i=0;$i<$count;$i++){
$sql1=mysql_query("UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', midmark='$midmark[$i]' WHERE id='$id[$i]' ");
$result1=mysql_query($sql1);
}
}
if(isset($result1)){
header("location:multiple.php");
}
mysql_close();
?>