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 926385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:40:41+00:00 2026-05-15T19:40:41+00:00

I am using sessions to pass user information from one page to another. However,

  • 0

I am using sessions to pass user information from one page to another. However, I think I may be using the wrong concept for my particular need. Here is what I’m trying to do:

  1. When a user logs in, the form action is sent to login.php, which I’ve provided below:

login.php

$loginemail = $_POST['loginemail'];     

$loginpassword = md5($_POST['loginpassword']);  

$con = mysql_connect("xxxx","database","pass");  
if (!$con)  
    {      
  die('Could not connect: ' .mysql_error());  
    }  

mysql_select_db("db", $con);  

$result = mysql_query("SELECT * FROM Members  
WHERE fldEmail='$loginemail'   
and Password='$loginpassword'");


//check if successful  
if($result){  
    if(mysql_num_rows($result) == 1){  
            session_start();  
            $_SESSION['loggedin'] = 1; // store session data  
            $_SESSION['loginemail'] = fldEmail;  
    header("Location: main.php"); } 
}  
mysql_close($con);  
  1. Now to use the $_SESSION[‘loggedin’] throughout the website for pages that require authorization, I made an ‘auth.php’, which will check if the user is logged in.

The ‘auth.php’ is provided below:

session_start();        
if($_SESSION['loggedin'] != 1){  
header("Location: index.php"); }  
  1. Now the point is, when you log in, you are directed BY login.php TO main.php via header. How can I echo out the user’s fullname which is stored in ‘fldFullName’ column in MySQL on main.php? Will I have to connect again just like I did in login.php? or is there another way I can simply echo out the user’s name from the MySQL table? This is what I’m trying to do in main.php as of now, but the user’s name does not come up:

    $result = mysql_query("SELECT * FROM Members  
    WHERE fldEmail='$loginemail'     
        and Password='$loginpassword'");  
    
    //check if successful  
    if($result){  
        if(mysql_num_rows($result) == 1){  
            $row = mysql_fetch_array($result);  
              echo '<span class="backgroundcolor">' . $row['fldFullName'] .       '</span><br />' ;  
    
  • 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-05-15T19:40:41+00:00Added an answer on May 15, 2026 at 7:40 pm

    Will I have to connect again just like I did in login.php?

    Yes. This is the way PHP and mysql works

    or is there another way I can simply echo out the user’s name from the MySQL table?

    No. To get something from mysql table you have to connect first.
    You can put connect statement into some config file and include it into all your scripts.

    How can I echo out the user’s fullname which is stored in ‘fldFullName’ column in MySQL on main.php?

    You will need some identifier to get proper row from database. email may work but it’s strongly recommended to use autoincrement id field instead, which to be stored in the session.
    And at this moment you don’t have no $loginemail nor $loginpassword in your latter code snippet, do you?

    And some notes on your code

    1. any header("Location: "); statement must be followed by exit;. Or there would be no protection at all.

    2. Any data you’re going to put into query in quotes, must be escaped with mysql_real_escape_string() function. No exceptions.

    so, it going to be like this

    include $_SERVER['DOCUMENT_ROOT']."/dbconn.php";
    
    $loginemail = $_POST['loginemail'];     
    $loginpassword = md5($_POST['loginpassword']);  
    
    $loginemail = mysql_real_escape_string($loginemail);     
    $loginpassword = mysql_real_escape_string($loginpassword);  
    
    $query = "SELECT * FROM Members WHERE fldEmail='$loginemail' and Password='$loginpassword'";
    $result = mysql_query($query) or trigger_error(mysql_error().$query);
    
    if($row = mysql_fetch_assoc($result)) {  
      session_start();  
      $_SESSION['userid'] = $row['id']; // store session data  
      header("Location: main.php"); 
      exit;
    } 
    

    and main.php part

    session_start();
    if(!$_SESSION['userid']) {
      header("Location: index.php"); 
      exit;
    } 
    include $_SERVER['DOCUMENT_ROOT']."/dbconn.php";
    
    $sess_userid = mysql_real_escape_string($_SESSION['userid']);
    $query  = "SELECT * FROM Members  WHERE id='$sess_userid'";  
    $result = mysql_query($query) or trigger_error(mysql_error().$query);
    $row = mysql_fetch_assoc($result));
    
    include 'template.php';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a Session variable to pass a datatable from 1 page to
I have been considering the problems arising with user authentication, using sessions/cookies and the
As the title says, is there another way to pass a variable from "current"
I am using session_start(); at the top of my login page. After a user
I am using Asp.NET MVC 3. In one particular use case, I need to
I tried to make admin panel and I am using sessions , but have
I have a website, im using sessions for the login. In every pages of
Does anybody try zf2? I can not understand new mechanism of using sessions in
During many, sometimes inundating, debugging sessions using DDD, I stumble upon loops. And I
So, For the sake of performance, I'm using database sessions. I figure that while

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.