gpt4 book ai didi

php - 如何显示特定用户拥有的数据?

转载 作者:行者123 更新时间:2023-11-28 03:09:12 24 4
gpt4 key购买 nike

我正在进行以下项目:基本上用户可以将一本书添加到数据库中。我要实现的是显示特定用户在其用户配置文件中添加的书籍的image。这样当用户登录时,他们就能看到他们添加的所有书籍的图像。
我有两个名为bookuser的表,其中连接了字段id

if (isset($_SESSION['user_id'])) {
$msg = "You are already logged in.<br/><a href='index.php'>Home</a>";
$msg = "<a href ='logout.php'>logout</a>";
} else { //user is not logged in
//check whether form input 'username' contains value
if (isset($_POST['username'])) {
//retrieve form data
$entered_username = $_POST['username'];
$entered_password = $_POST['password'];
//connect to database
include ("dbfunctions.php");
//match the username and password entered with database record
$query = "SELECT *from role,user
WHERE user_name='$entered_username' AND
PASSWORD = SHA1('$entered_password') AND user.role_id = role.role_id";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
$query2 = "SELECT * FROM user,country where user.country_id=country.country_id ORDER BY `user`.`id` ASC";
$result2 = mysqli_query($link, $query2) or die(mysqli_error($link));
$query3 = "SELECT * FROM user, book WHERE book.id = user.id ";
$result3 = mysqli_query($link, $query3) or die(mysqli_error($link));

if (mysqli_num_rows($result) == 1) {
$update = "UPDATE `user` SET last_login = NOW() WHERE user_name='$entered_username' ";
$resultupdate = mysqli_query($link, $update);
$row = mysqli_fetch_array($result);
$_SESSION['user_id'] = $row['id'];
$_SESSION['username'] = $row['user_name'];
$_SESSION['email'] = $row['email_address'];
$_SESSION['gender'] = $row['gender_id'];
$_SESSION['role_id'] = $row['role_type'];
$_SESSION['lastlog'] = $row['last_login'];
$msg1 = $_SESSION['username'];
$msg2 = "<b>Gender: </b> " . $_SESSION['gender'] . "<br/>";
$msg3 = "<b>Email: </b>" . $_SESSION['email'] . "<br/>";
$msg4 = "<b>Your last visit on this site: </b>" . $_SESSION['lastlog'];


} else { //record not found
echo "No record found";

}
}
}

if (mysqli_num_rows($result3) == 1) {

$rowz = mysqli_fetch_array($result3);
$_SESSION['img'] = $rowz['image'];
$image= $_SESSION['img'];

} else { //record not found
echo "No record found";

}
?>
......................................................................................

html:
  <?php
} elseif ($_SESSION['role_id'] == "Member") {
?>
<div class="panel panel-default">
<div class="panel-heading"><i>Books</i> you add</div>
<div class="panel-body"><?php echo $image;?></div></div>
}

这样做之后,当我尝试为每个示例用户登录时,即使图像仅由1个用户添加,也会出现相同的图像。我该怎么解决?

最佳答案

检查下面的代码(来自您提供的示例)

if (mysqli_num_rows($result3) == 1) {

}

关于php - 如何显示特定用户拥有的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31285636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com