[英]How Do I show a users Email address from MYSQL?
I'm trying to get it where, when the user goes to their profile, it will show them their email address. 我正在尝试将其保存在哪里,当用户转到其个人资料时,它将向他们显示其电子邮件地址。 I have it where it shows their username by using $_SESSION['username'] but when I try that for the EMAIL address it doesn't work.
我使用$ _SESSION ['username']在显示用户名的位置使用了它,但是当我尝试使用该地址作为EMAIL地址时,则不起作用。 Any Ideas on how I can get it to SELECT the email address from the Database?
关于如何从数据库中选择电子邮件地址的任何想法? Thank You In Advance!!
先感谢您!! :)
:)
It's showing their current Email address: and then the code.
它显示了他们当前的电子邮件地址:然后是代码。 Here's my PHP:
这是我的PHP:
Includes/config.php is getting the DATABASE INFO. Includes / config.php正在获取数据库信息。
<?php require('includes/config.php');
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: login.php?action=login'); }
?>
Includes/config.php 包括/ config.php文件
<?php
ob_start();
session_start();
//set timezone
date_default_timezone_set('Europe/London');
//database credentials
define('DBHOST','localhost');
define('DBUSER','xxxxx');
define('DBPASS','xxxxx');
define('DBNAME','bigfellamembers');
//application address
define('DIR','http://xxxxxxxxxxx.com');
define('SITEEMAIL','noreply@domain.com');
try {
//create PDO connection
$db = new PDO("mysql:host=".DBHOST.";dbname=".DBNAME, DBUSER, DBPASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
//show error
echo '<p class="bg-danger">'.$e->getMessage().'</p>';
exit;
}
//include the user class, pass in the database connection
include('classes/user.php');
include('classes/phpmailer/mail.php');
$user = new User($db);
?>
Here's my database table. 这是我的数据库表。
Heres: some of my HTML: 继承人:我的一些HTML:
<!-- row -->
<div class="row">
<div class="col-md-12">
<div class="white-box">
<div class="user-bg"><img width="100%" alt="user" src="login-bg.jpg">
<div class="overlay-box">
<div class="user-content">
<a href="javascript:void(0)"><img src="uploads/<?php echo $_SESSION['username']; ?>.jpg" class="thumb-lg img-circle" alt="img"></a>
<h4 class="text-white">Current Username: <?php echo $_SESSION['username']; ?> </h4>
<h5 class="text-white">Current Email Address: <?php echo $_SESSION['email']; ?>
</div>
</div>
</div>
If you haven't set the email within the SESSION then you can't try and grab it like that. 如果您尚未在SESSION中设置电子邮件,则无法尝试像这样抓住它。
You'll need to use a MySQL query (research PDO) to grab the email from the database based on some criteria (eg username). 您将需要使用MySQL查询(研究PDO)根据某些条件(例如用户名)从数据库中获取电子邮件。
You first need to get the user Email from database, Let's say 首先,您需要从数据库中获取用户电子邮件,例如
Query: 查询:
"SELECT email from user WHERE username ='$username' ";
After running the query and fetching your data from database, you can then do these: $_SESSION['email'] = $result['email'];
运行查询并从数据库中获取数据后,您可以执行以下操作:
$_SESSION['email'] = $result['email'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.