所以我有两页。一个显示填写表单的所有用户。在此页面上,ID被超链接到用户个人页面。在单个页面上,它应该只显示其个人信息。当我这样做时,它仍然显示每个人的信息,我无法弄清楚如何改变它。
这是我所有用户的表格。
<?php
//Establish the connection to the database server
$conn = mysql_connect("localhost","root", "MIS42520!$") or die (mysql_error());
//Tell the connection which database to user_error
mysql_select_db("assignment_3", $conn);
//Tell the database what you want, with an SQL statement
$sql = "select id, firstname, lastname, emailaddress from usertable";
//Run the sql statement against the connection
$result = mysql_query($sql, $conn) or die (mysql_error());
//Process the result set $result
print "<center><table id='adminTable' border=1>";
print "<tr><th>ID</th><th>First Name</th><th>Last Name</th> <th> Email Address</th> </tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td><a href=\"showUser.php?id={$row['id']}\">{$row['id']}</a></td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['emailaddress'] . "</td></tr>";
}
echo "</table></center>"; //Close the table
?>
我对单个用户的表基本上完全相同,但我在顶部添加了以下内容
$id= $_GET['id'];
答案 0 :(得分:1)
将您的$sql
变量更改为:
$sql = "select id, firstname, lastname, emailaddress from usertable where id='".htmlentities($_GET['id'])."'";
答案 1 :(得分:-1)
嗯..您需要更改我认为的唯一一个用户的页面的语句 试试这个
$sql = "select id, firstname, lastname, emailaddress from usertable where id =".$id;
正如@ jay-blanchard在评论中所说的那样,尽量不要使用已弃用的方法/条款,在这里使用准备好的语句是mysqli
类的链接