这是我在表用户中显示所有数据的编码。文件名为 admindisplay.php
<?php
//Establish Server Connection String
//Connect to database
include('server.php');
session_start();
//Query database and set result to variable
$result = mysql_query ("SELECT * FROM user");
//Generate Table
echo "<table border='1'><tr><th>No</th><th>Name</th><th>Department</th><th>Date</th><th>Issue</th><th>Details</th><th>Assign Person</th><th>Status</th></tr>";
while($row = mysql_fetch_array($result))
{
$No = $row ['No'];
echo "<tr>";
echo "<td>" . $row['No'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "<td>" . $row ['Date'] . "</td>";
echo "<td>" . $row ['Issue'] . "</td>";
echo "<td>" . $row ['Details'] . "</td>";
echo "<td>" . $row ['Assignperson'] . "</td>";
echo "<td>" . $row ['Status'] . "</td>";
echo "<td><form action=\"adminassign.php\" method=\"POST\">
Note: <input type=\"text\" size=\"40\" maxlength=\"100\" name=\"note\">
<label>Assign to:</label>
<select name=\"assign\">
<option value=\"\">-Choose-</option>
<option value=\"Adrian\">Adrian</option>
<option value=\"Trainee\">Trainee</option>
</select>
<input name=\"Nos\" type=\"hidden\" value=\"$No\">
<input name=\"submit\" type=\"submit\" value=\"Assign\"</td>";
}
echo "</table>";
?>
这是我更新我想要的任何行的编码。文件名是 adminassign.php
<?php
//Establish Server Connection String
//Connect to database
include('server.php');
session_start();
$No = $_POST ['Nos'];
$Note = $_POST['note'];
$Assign = mysql_real_escape_string(htmlspecialchars($_POST['assign']));
if($Assign=='Adrian')
{
mysql_query("UPDATE user SET Assignperson = 'Adrian' WHERE No = '$No'");
mysql_query("UPDATE user SET Note = '$Note' WHERE No = '$No'");
echo "assign successful";
}
else
{
if($Assign=='Trainee')
{
mysql_query("UPDATE user SET Assignperson = 'Trainee' WHERE No = '$No'");
mysql_query("UPDATE user SET Note = '$Note' WHERE No = '$No'");
echo "assign successful";
}
}
?>
<form action="index.php" method="POST">
<p><input type="submit" value="Log Out">
</form>
<form action="admindisplay.php" method="POST">
<p><input type="submit" value="Back">
</form>
现在的问题是,我只能更新最后一行,不能更新上一行。谁能帮我解决这个问题?