[英]How to Show Profile Picture of User on Change password form (Picture of Logged In user should be show) in HTML/PHP
我正在做一个小项目,我已经创建并链接了更改密码表单并使用了更新查询,表单工作得很好,但我想在更改密码表单上显示用户的图像,下面是我的代码,当我使用时session 变量并在表单中添加 php 代码,然后我已经固定的图像也被隐藏了,而我不想显示固定图像我想显示用户的图像,请帮我纠正它。 我使用了 if else 和 switch 语句,但只有 else 语句正在执行。
<div class="container">
<h1>CHANGE YOUR PASSWORD</h1>
<div class="contact-form">
<div class="profile-pic">
<?php
if (isset($_SESSION['username'])){
$username = !empty($_SESSION['username']) ? $_SESSION['username'] : false;
switch ($username) {
case 'admin':
case 'Admin':
case 'ADMIN':
?>
<img src="profile_pics/4.png" alt="User Icon"/>
<?php
break;
case 'muhammad azeem':
case 'Muhammad Azeem':
case 'MUHAMMAD AZEEM':
?>
<img src="profile_pics/1.png" alt="User Icon"/>
<?php
break;
case 'muhammad adnan':
case 'Muhammad Adnan':
case 'MUHAMMAD ADNAN':
?>
<img src="profile_pics/2.png" alt="User Icon"/>
<?php
break;
case 'saleem raza':
case 'Saleem Raza':
case 'SALEEM RAZA':
?>
<img src="profile_pics/3.png" alt="User Icon"/>
<?php
break;
case 'abdul raheem':
case 'Abdul Raheem':
case 'ABDUL RAHEEM':
?>
<img src="profile_pics/5.png" alt="User Icon"/>
<?php
break;
}
} else{
?>
<img src="images/1.png" alt="User Icon"/>
<?php
}
?>
</div>
<div class="signin">
<form action="process_change_password_form.php" method="POST">
<input type="text" name="current_password" class="user"
value="Current Password"
onfocus="this.value = '';"
onblur="if (this.value == '') {this.value = 'Current Password';}"
id="1" required>
<input type="text" name="new_password" class="user"
value="New Password"
onfocus="this.value = '';"
onblur="if (this.value == '') {this.value = 'New Password';}"
id="1" required>
<input type="text" name="confirm_new_password" class="user"
value="Confirm New Password"
onfocus="this.value = '';"
onblur="if (this.value == '') {this.value = 'Confirm Password';}"
id="1" required>
<input type="submit" value="Change Password" name="submit" />
</form>
</div>
</div>
</div>
</body>
</html>
您必须使用以下命令更改您的 switch 语句:
<?php
$img = '1.png'; //Default image
switch (strtolower($username)) {
case 'admin':
$img = '4.png';
break;
case 'muhammad azeem':
$img = '1.png';
break;
...
}
echo '<img src="profile_pics/'.$img.'" alt="User Icon"/>';
?>
strtolower() 将所有字符转换为小写,因此您只能检查一次 $username 的大小写。
无论如何,我建议您删除开关功能并将配置文件图像文件保存在会话变量中,然后简单地使用
echo '<img src="profile_pics/'.$_SESSION['img_file'].'" alt="User Icon"/>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.