gpt4 book ai didi

php - 为所有用户而不是某一用户显示个人资料图片

转载 作者:行者123 更新时间:2023-11-29 11:38:25 25 4
gpt4 key购买 nike

大家好,我正在尝试创建我的个人资料照片以供我的用户上传。我已经让它为用户工作,所以你可以登录上传等,然后注销,一切正常,但是目前它显示每个用户的个人资料图片,而不是当时登录的特定图片

id 
user_name
password
profilePic set it as text

我的 PHP:

<?php
mysql_connect("localhost","root","") or die ("could not connect");
mysql_select_db("reg") or die ("could not find db");
session_start();

if(!$_SESSION['username']){
header("location: login.php");
}

$favs = array();
$links = array();
$sql = "SELECT * FROM recipe WHERE fav='yes'";
$records = mysql_query($sql);
//while($result =mysql_fetch_assoc($records)){
//$favs[] = $result['recipeName'];
//$links[] = $result['url'];
//}
$user_name = $_SESSION['username'];

if(isset($_POST['submit'])){
move_uploaded_file($_FILES['file']['tmp_name'],
"Image/userImages/".$_FILES['file']['name']);
$con = mysqli_connect("localhost","root","","reg");
$q = mysqli_query($con,"UPDATE users SET profilePic = '".
$_FILES['file']['name']."' WHERE user_name = '".$_SESSION['username']."'");
}

?>

html:

<div class = "pic">
<?php
$con = mysqli_connect("localhost","root","","reg");
$q = mysqli_query($con,"SELECT * FROM users");
while($row = mysqli_fetch_assoc($q)){
if($row['profilePic'] == ""){
echo "<img width='100' height='100'
src='Image/userImages/profile.png' alt='Default Profile Pic'>";
} else {
echo "<img width='100' height='100'
src='Image/userImages/".$row['profilePic']."' alt='Profile Pic'>";
}
echo "<br>";
}
?>

<div class="userNameText">
<?php echo $_SESSION['username'];?>
</div>
</div>

这与此有关: $q = mysqli_query($con,"SELECT * FROM users"); 我尝试将其更改为 $q = mysqli_query($con, "SELECT * FROM users WHERE user_name = $user_name"); 但运气不好,所以回到了几乎有效的东西。无论如何,对此事的任何帮助都会很棒

最佳答案

改变

$q = mysqli_query($con,"SELECT * FROM users");

$q = mysqli_query($con,"SELECT * FROM users where user_name = '".$_SESSION['username']."'");

你忘了添加''到哪里,如果该html与php在同一个文件中,那么你可以使用$user_name,如果不是,你必须使用session

关于php - 为所有用户而不是某一用户显示个人资料图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36241134/

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