0

这是我在表用户中显示所有数据的编码。文件名为 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>    

现在的问题是,我只能更新最后一行,不能更新上一行。谁能帮我解决这个问题?

4

2 回答 2

0

是的,这很简单,您必须使用它

<input name=\"Nos\" type=\"hidden\" value=\"$No\">

每当您提交此文件时,他们都会提交最后记录数据,因此您可以使用替代方案

<td><a href='adminassign.php?id=<?php echo $row['No']; ?>'>Edit</a></td>

这可能对你有帮助!!!!

于 2012-11-19T06:56:54.537 回答
0

您错过了表格中每一行中每个表单的结束标记:

</form>

然后,您只有一个具有许多 Nos 输入的表单,并且只考虑最后一个。

第一个代码示例中 while 循环的最后一行应该是:

<input name=\"submit\" type=\"submit\" value=\"Assign\" /></form></td>";

您的代码中还有其他语法问题(例如缺少右括号 > )。此类问题可以通过html代码的验证器捕获:http: //validator.w3.org/

于 2012-11-19T06:57:36.843 回答