Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8760927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:09:53+00:00 2026-06-13T15:09:53+00:00

I have set up a login page for mySQL and it logs in correctly.

  • 0

I have set up a login page for mySQL and it logs in correctly. The login form has e-mail and password but when they log-in. When they first register though, their mySQL record is populated with their first and last name as well (the fields are first name, last name, e-mail, password).

The problem is that when I login successfully, it’s not grabbing the other variables from the record. It’s just grabbing the e-mail and password because that’s what they input. How do I grab the other variables of a row in mySQL (first name, last name) that correspond with data I already have (username, password)? I understand this may be sort of mySQL 101 but I’m having trouble Googling this question exactly.

I’ve attached some code. This is my checklogin.php page that validates everything. Now I understand that the variables at the bottom are not the way I get the firstname and lastname since they weren’t posted by the form (as I mentioned, the form only has e-mail and password):

<?php
$mysqli = mysqli_connect("mysql_name","user_name","password", "db_name");
if (!$mysqli)
  {
  die('Could not connect: ' . mysqli_error($mysqli));
  }

// username and password sent from form
//NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection!
$email=$mysqli->real_escape_string($_POST['email']);
$password=$mysqli->real_escape_string($_POST['password']);

$sql="SELECT * FROM tbl_name WHERE email='$email' and password='$password'";
$result = $mysqli->query($sql);

if(is_object($result) && $result->num_rows == 1){
  // Register variables and redirect to file "profile.php"
  session_start();
  $_SESSION['firstname']=$_POST['firstname'];
  $_SESSION['lastname']=$_POST['lastname'];
  $_SESSION['email']=$_POST['email'];
  $_SESSION['password']=$_POST['password'];
  header('location:profile.php');
} else {
  echo "Wrong Username or Password";
}
?>

My assumption is that the variables are called on the profile.php page that this gets redirected to after I start the session. The problem is $_SESSION[‘firstname’] and $_SESSION[‘lastname’] don’t work because I suppose they haven’t been declared yet. Any help (or even just a nudge in the right direction) would be greatly appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:09:55+00:00Added an answer on June 13, 2026 at 3:09 pm
    Try This if you have all the information in the same table:    
    
    
    <?php
        $mysqli = mysqli_connect("localhost","root","", "login");
        if (!$mysqli)
          {
          die('Could not connect: ' . mysqli_error($mysqli));
          }
    
        // username and password sent from form
        //NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection!
        $email=$mysqli->real_escape_string($_POST['email']);
        $password=$mysqli->real_escape_string($_POST['password']);
    
        $sql="SELECT * FROM tbl_name WHERE email='$email' and password='$password'";
        $result = $mysqli->query($sql);
    
        if(is_object($result) && $result->num_rows == 1){
          // Register variables and redirect to file "profile.php"
          session_start();
          $num=$result->fetch_array(MYSQLI_ASSOC);
          $_SESSION['firstname']=$num['firstname'];
          $_SESSION['lastname']=$num['lastname'];
          $_SESSION['email']=$num['email'];
          $_SESSION['password']=$num['password'];
          //redirect('profile.php');
          header('location:profile.php');
        } else {
          echo "Wrong Username or Password";
        }
    
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have set up a login page that verifies the user's credentials, and
I have a login page written in classic asp. I want to set the
I have a login form that when submitted; redirects back to the login page.
I have 3 pages in my set up here: login.php: The login page that
On Ubuntu Linux, with Bash, I have /etc/profile set with read-only variables on login.
I have a login window with a Sign In button which is set as
I have set a background on the data-role=page element like so <div data-role=page style=background:
I have a demo of gcm working here: http://leobee.com/android/push/login/gcm/updateusers.php If you refresh the page,
Hello I have a question. I have set up my login system with cookies
I have a php page that pulls data from a mysql database based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.