希望有人可以在这里帮助我,我创建了一个有多个用户的系统,每个用户都有一个唯一的用户名和 ID。我现在的问题是如何设置我的系统,当用户登录时,系统将指导用户根据他们的用户名或 id 查看数据库中的特定行。
我访问数据库的代码是:
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("uloaku", $con);
$count = 1;
$y = mysql_query("SELECT * FROM transaction WHERE username = '".$_SESSION['username']."' LIMIT 1");
if(mysql_num_rows($y) != 0){
echo "<table border=\"1\" width=\"800\" >";
echo "<tr id=\"bold\">
<td>No</td>
<td align=\"center\" width=\"120\">Account Owner</td>
<td align=\"center\" width=\"120\">Deposit Date</td>
<td align=\"center\" id=\"bold\" width=\"150\">Current Balance</td>
<td align=\"center\" width=\"150\">Available Balance</td>
<td align=\"center\">Account Status</td>
</tr>";
while ($z = mysql_fetch_array($y, MYSQL_BOTH)){
echo "<tr>
<td>".$count++."</td>
<td id=\"color\" align=\"center\">".$z[1]."</td>
<td id=\"color\" align=\"center\">".$z[2]."</td>
<td id=\"color\" align=\"center\">".$z[3]."</td>
<td id=\"color\" align=\"center\">".$z[4]."</td>
<td id=\"color3\" align=\"left\">".$z[5]."</td>
</tr>";
}
echo "</table>";
}
?>
我的登录页面如下所示:
<?php
session_start();
$_SESSION['username'] = $username;
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$connect = mysql_connect("localhost","root","") or die("cannot connect!");
mysql_select_db("uloaku") or die("cannot find data base!");
$query = mysql_query ("SELECT * FROM keyaku WHERE username='".mysql_real_escape_string($username)."' AND password='".mysql_real_escape_string($password)."'");
$numrows = mysql_num_rows($query);
if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
if ($username==$dbusername&&$password=$dbpassword)
{
echo "Welcome $username";
}
else
echo "Invalid Password";
}
else
die("Invalid User");
}
else
die("Please Enter a UserName and Password.");
?>
到目前为止,我的登录正在按我的意愿工作,我的数据库检索信息唯一的问题是它检索数据库中的所有信息,但我希望它根据登录人的用户名或 ID 检索信息在