简体   繁体   中英

How to retrieve data from SQL database for a logged in user

I want to have a profile page so the logged in user can view their personal information. Im able to display the current logged in username but unable to display any other information. The remaining data is stored within the same table as the username.

<?php
define('DB_HOST', 'localhost'); 
define('DB_NAME', 'Pole_Fitness'); 
define('DB_USER','root'); 
define('DB_PASSWORD','root'); 

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error()); 
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error()); 

session_start(); 
$_SESSION['userName']
$userName = $_SESSION['userName']

    $getquery=mysql_query("SELECT * FROM WebsiteUsers WHERE userName = '$userName'");
    while($rows=mysql_fetch_assoc($getquery))
    {
    $FirstName=$rows['FirstName'];
    $LastName=$rows['LastName'];
    $DOB=$rows['DOB'];

    echo $FirstName . '<br/>' . '<br/>' . $LastName . '<br/>' . '<br/>' . $DOB '<hr size="3"/>';
    }
    ?>

you seem to be missing a . , as concatenate operator, just after you $DOB variable on the line where you get to print the data. Can you make sure that it goes like this:

 echo $FirstName . '<br/><br/>' . $LastName . '<br/><br/>' . $DOB . '<hr size="3"/>';

I joined both break tags to make it more concise. Also those session assignments you did seems to be out of place, let's clean it up a bit:

session_start(); 
//$_SESSION['userName'] - how bout commenting this out
$userName = $_SESSION['userName']; //missing ampersand

Take note that mysql_query is deprecated as of PHP 5.5.0, so you might want to use mysqli extensions instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM