Jump to content

Sessions and understanding SQL / requires


Pandee

Recommended Posts

Hello!

So i have an echo like such

<?php echo $_SESSION['email']; ?>

Is there documentation or perhaps provide an example where/how I can pull this email from the same row of information in the MySQL database? Doing this without a require_once php page that has this information?

 

Googling didn't really help.

 

Many thanks for being part of my journey!

Edited by Pandee
Link to comment
Share on other sites

  • Pandee changed the title to Sessions and understanding SQL / requires
        $sql = "SELECT username, verified, email FROM users WHERE username, verified, email";
         
        if($stmt = mysqli_prepare($link, $sql)){
            // prepare statements as parameters
            mysqli_stmt_bind_param($stmt, "sis", $param_username, $param_verified, $param_email);
            
            //  parameters
            $param_username = $username;
            $param_email = $email;
            $param_verified = $verified;

            if(mysqli_stmt_execute($stmt)){
                // 
                $_SESSION['username'] = $user['param_username'];
                $_SESSION['verified'] = $user['param_verified'];
                $_SESSION['email'] = $user['param_email'];

            } else{
                //empty
            }

            // empty
            
        }

Above is code I have been trying to get to work. I believe something is wrong with my select statement that you recommended me to use (also thanks). I can tell because when I try to do the below code...

 

<?php echo $_SESSION['username']; ?>

<?php echo $_SESSION['verified']; ?>

<?php echo $_SESSION['email']; ?>

Username is echo'd and email and verified does not.

 

Thanks once again!

Link to comment
Share on other sites

So I have set up a different page which has inserted their Username / Password / Token / Email and verified set to 0 when registration is successful. 

When I enter the welcome.php file it would echo the Username and Email to let them know who they are logged in as and what address the verification email was sent to.

Link to comment
Share on other sites

Then

$stmt = mysqli_prepare($link, "SELECT username
                                    , verified
                                    , email 
                               FROM users 
                               WHERE id = ?
                               ");
mysqli_stmt_bind_param($stmt, "i", $_SESSION['id']);         
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $username, $verified, $email);
mysqli_stmt_fetch($stmt);

echo "$username, $email, $verified";

However, I'd recommend using PDO instead of mysqli

$stmt = $pdolink->prepare("SELECT username
                                , verified
                                , email 
                           FROM users 
                           WHERE id = ?
                           ");
$stmt->execute([$_SESSION['id']]);
$row = $stmt->fetch();
echo "{$row['username']}, {$row['email']}, {$row['verified']}"              

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.