1

I simply need to display data from a mysql database. All the data is already stored in the database when the user submits the form. So in the landing page after the user is logged in, I need to display the users full name as well as a few other columns from the database table. In essence, I want the page to say Welcome fullname, then display some other colums from the database in a table. How should I code this using session? NOTE: I have tried to use sessions to display the user's full name and current balance after logging in. My code below:

<?php
    // Connect to database display welcome Full name, then date, name, credit, debit, balance
    session_start();
    $fullname="";

    $currentbalance="";
    if (!isset($_SESSION)){
    session_start();
    }
    echo $_SESSION['fullname'];


    ?>
    Welcome <?php echo $_SESSION['fullname']; ?>.
    <table border ="1">
    <th>DATE </th>
    <th>'.$fullname.' </th>
    <th>CREDIT </th>
    <th>DEBIT</th>
    <th><?php echo $_SESSION['currentbalance']; ?</th>
    </table>
2
  • 1
    you need to assigned value to variable $_SESSION['fullname'] = $fullname and before using it you need to start the session Commented Mar 5, 2013 at 8:20
  • ok i will try that now. Is that all I didn't do though? Commented Mar 5, 2013 at 8:22

4 Answers 4

2

When you logged in you need to store fullname in session like

$_SESSION['fullname'] = $_REQUEST['fullname'];

After login , you can get this fullname on homepage.

$session_name = $_SESSION['fullname'];
Sign up to request clarification or add additional context in comments.

Comments

1
<?php
    // Connect to database display welcome Full name, then date, name, credit, debit, balance
    if (!isset($_SESSION)){
    session_start();
    }
    $fullname="";
    $currentbalance="";

    $_SESSION['fullname']=$fullname;
$_SESSION['currentbalance ']=$currentbalance ; // Where $fullname and $currentbalance must be already defined by the query


    ?>
    Welcome <?php echo $_SESSION['fullname']; ?>.
    <table border ="1">
    <th>DATE </th>
    <th>'.$fullname.' </th>
    <th>CREDIT </th>
    <th>DEBIT</th>
    <th><?php echo $_SESSION['currentbalance']; ?</th>
    </table>

Comments

0

During login just store the user id into session, so you could easily got all the information from database by this user id.

"select * from `users` where id='".$_SESSION['userid']."'"

2 Comments

Ok, but how do I store the user id into session?Because the user's full name is only supposed to be displayed after log in
If you'r about show the full name only then store the full name in session.
0

use this code, you put the session in curly braces.

"select * from `users` where id={$_SESSION['userid']}"

1 Comment

Please use prepared statements rather than putting values directly into query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.