由于一些奇怪的原因,数据库没有更新。我可以获取信息,但是单击提交时它不会更新。有没有什么遗漏。
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpwd = 'ALLO';
$dbname = 'test_db';
$con = mysql_connect($dbhost, $dbuser, $dbpwd );
if(! $con )
{
die("\$con: $con \nCould not connect: " . mysql_error());
}
$select_db=mysql_select_db($dbname);
$strquery = "SELECT * from Students WHERE Age='99'";
$results = mysql_query ($strquery);
$row = mysql_fetch_array($results);
?>
<body>
<table align="center">
<tr>
<td>
<form id="update" name="update" method="POST" action="update.php">
<table border="0" bgcolor="#6699CC" cellpadding="0" cellspacing="1">
<tr bgcolor="#6699CC">
<td colspan="2" align="center">Edit Student Records</td>
</tr>
<tr bgcolor="#FFFFFF">
<td>F NAME :</td>
<td><input name="fname" type="text" id="fname"
value=" <?php echo $row["FirstName"]; ?> " /></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>L NAME :</td>
<td><input name="lname" type="text" id="lname"
value=" <?php echo $row["LastName"]; ?> " /></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Age :</td>
<td><input name="age" type="text" id="age"
value=" <?php echo $row["Age"]; ?>" /></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2" align="center"><input type="submit" name="Submit"
value="Update" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
更新.PHP:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpwd = 'ALLO';
$dbname = 'test_db';
$connect = mysql_connect($dbhost, $dbuser, $dbpwd);
if (!$connect) {
die("\$connect: $connect \nCould not connect: " . mysql_error());
}
$select_db = mysql_select_db($dbname);
$strquery = "
UPDATE Students
SET FirstName = '" . $_POST['fname'] . "',
LastName = '" . $_POST['lname'] . "',
WHERE
Age = '" . $_POST['age'] . "'
";
$results = mysql_query($strquery);
header('location: displaytb.php ');
?>
我认为这是无法正常工作的更新,因为其他一切似乎都很好。displaytb.php 只是显示数据库,但内容没有更新。