简体   繁体   English

如何显示来自MYSQL的用户电子邮件地址?

[英]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. 这是我的数据库表。 数据库 datbase

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.

相关问题 如何从电子邮件地址获取Linkedin的头像 - How do I get Linkedin's avatars from an email address Laravel 8:我如何在注册后验证用户的电子邮件地址而无需提供登录信息? - Laravel 8: How do i verify the users email address after registration without having to require login information? 如何设置入站邮件控制器,以便用户可以发布到唯一的电子邮件地址? - How do I set up an inbound mail controller so users can post to unique email address? 如何为用户显示电子邮件地址但是隐藏机器人? 有没有一种简单的方法来使用PHP,Javascript或Jquery? - How to display an email address for users but hide from robot? Is there a simply way to do it using PHP, Javascript or Jquery? Laravel 8 我们如何获得认证用户 email 地址 - Laravel 8 how do we get authenticated users email address 如何提取电子邮件地址? - How do I pull email address? 在将数据发送到mySQL之前,如何清理用户的数据? - How do I sanitize data from users before sending it to mySQL? 如何限制用户在RS Forms Joomla中注册公司电子邮件地址以外的公共电子邮件地址 - How to restrict users from Registering public email addresses other than company email address in RS Forms Joomla 如何使用 php 发送 email,其中收件人地址从 mySQL 中选择? - How to send a email with php where the recipient address is selected from mySQL? 如何更改与PHP联系表单关联的“来自电子邮件地址” - How do I change the “from email address” associated with PHP contact form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM