Php 如何向1个用户显示mySQL信息
所以我有两页。其中一个显示已填写表单的所有用户。在此页面上,ID超链接到用户个人页面。在个人页面上,它应该只显示他们的个人信息。当我这样做的时候,它仍然显示每个人的信息,我不知道如何改变它 这是我为所有用户准备的表格Php 如何向1个用户显示mySQL信息,php,mysql,sql,Php,Mysql,Sql,所以我有两页。其中一个显示已填写表单的所有用户。在此页面上,ID超链接到用户个人页面。在个人页面上,它应该只显示他们的个人信息。当我这样做的时候,它仍然显示每个人的信息,我不知道如何改变它 这是我为所有用户准备的表格 <?php //Establish the connection to the database server $conn = mysql_connect("localhost","root", "MIS42520!$") or die (mysql_error());
<?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
?>
嗯。。您需要更改我认为只有一个用户的页面的语句 试试这个
正如@jay blanchard在评论中所说的,尽量不要使用不推荐的方法/类别,使用预先准备好的语句这里是指向类的链接将
$sql
变量更改为:
$sql = "select id, firstname, lastname, emailaddress from usertable where id='".htmlentities($_GET['id'])."'";
请注意,它们已不再维护,并且是。而是学习,并使用或。
$sql = "select id, firstname, lastname, emailaddress from usertable where id =".$id;
$sql = "select id, firstname, lastname, emailaddress from usertable where id='".htmlentities($_GET['id'])."'";