我有 2 个文件,1)表格 2)更新文件
这是更新表单 update.php:
<?php
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="datasename"; // Database name
$tbl_name="data"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<div align="center"><img src="http://www.multihunters.co.uk/images/tf_ideal/blue/misc/logo.png" width="400" height="125">
</div>
<div align="center">
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>Citizen ID</strong></td>
<td align="center"><strong>Citizen Name</strong></td>
<td align="center"><strong>Citizenship</strong></td>
</tr>
<tr>
<td> </td>
<td align="center">
<input name="citid" type="text" id="citid" value="<? echo $rows['citid']; ?>">
</td>
<td align="center">
<input name="citname" type="text" id="citname" value="<? echo $rows['citname']; ?>" size="15">
</td>
<td>
<input name="citizenship" type="text" id="citizenship" value="<? echo $rows['citizenship']; ?>" size="15">
</td>
</tr>
<tr>
<td> </td>
<td>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit">
</td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</div>
<?php
// close connection
mysql_close();
?>
这是我的操作表单 update_ac.php:
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="database"; // Database name
$tbl_name="data"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
$sql="UPDATE $tbl_name SET citid='$citid', citname='$citname', citizenship='$citizenship' WHERE id='$id'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='http://www.multihunters.co.uk/citizens_permlist.php'>View result</a>";
}
else
{
echo "ERROR";
}
消息成功出现,但是当我检查数据是否已更新时,没有任何变化,我做错了什么?