Reputation:
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. 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:
Includes/config.php is getting the DATABASE INFO.
<?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
<?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','[email protected]');
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);
?>
Heres: some of my 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>
Upvotes: 0
Views: 3413
Reputation: 5
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'];
Upvotes: 0
Reputation: 2213
If you haven’t set the email within the SESSION then you can’t try and grab it like that.
You’ll need to use a MySQL query (research PDO) to grab the email from the database based on some criteria (e.g username).
Upvotes: 1