我有一个包含 2 个表的数据库,table1 只存储 id、用户名和密码,而 table2 存储 id、用户名、日期和其他信息。我现在的问题是如何设置我的代码,以便每次用户 A 登录并单击“查看个人资料”时,他或她只能根据那里的用户名而不是其他人的个人资料看到自己的个人资料。用户 B、用户 C 和用户 D 等也是如此。
我的日志代码是:
session_start();
$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.");
?>
我查看个人资料的代码是:
<?php
session_start();
$con = mysql_connect("localhost","root","");
mysql_select_db("uloaku", $con);
$count = 1;
$y = mysql_query("SELECT * FROM transaction WHERE id=24");
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=\"120\">Current Balance</td>
<td align=\"center\" id=\"bold\" width=\"90\">Intrest</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=\"color\" align=\"center\">".$z[5]."</td>
<td id=\"color3\" align=\"left\">".$z[6]."</td>
</tr>";
}
echo "</table>";
}
?>
希望有人可以帮助我,如果给出完整的代码或更正,我会非常感激,以便其他有类似问题的人可以参考并进行更正。谢谢