fife Posted July 6, 2008 Share Posted July 6, 2008 Hi. Im trying to display on a page the details of the person that has logged in and only thier details. Im starting nice and simple with trying to display just thier first name. This is so i get a better understanding of how it is done. Now the page i have made will only let you onto it as long as you have logged in on my signing in page. I have a table called members. I want to display a field called FirstName based upon thier login username which in my table is called UserName. I am very new to this so can someone point out my errors in my code? <?php session_start(); if (isset($_SESSION['Username'])) { $sql = "SELECT FirstName,data FROM Members WHERE id = UserName '{$_SESSION['FirstName']}'"; // execute query and display the page. } else { // user not logged in. }?> Also anybody know any good sites to learn php from as i am teaching myself at the minute? Thank you for your help! Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 6, 2008 Share Posted July 6, 2008 first of all please use code tags for code. second is there a session called FirstName and your query is wrong $sql = "SELECT FirstName,data FROM Members WHERE firstname = '{$_SESSION['FirstName']}'"; mysql_query($sql) or die("Error".mysql_error); if your table is called Username , why are you calling data from a table called members? and why are you selecting there details from where there id matches there username and you are not running the query either Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 6, 2008 Share Posted July 6, 2008 change $sql to this: $sql = "SELECT FirstName,data FROM Members WHERE id = UserName '" . $_SESSION['Username'] . "'"; then add this after it: $query = mysql_query($sql) or die("query failed " . mysql_error()); $row = mysql_fetch_array($query); echo $row['FirstName']; Regards ACE Quote Link to comment Share on other sites More sharing options...
fife Posted July 6, 2008 Author Share Posted July 6, 2008 lol mistake. my Username is a field in my members table Quote Link to comment Share on other sites More sharing options...
ron8000 Posted July 6, 2008 Share Posted July 6, 2008 Welcome to PHP! Its great stuff! Now there are lots of recources out there to help you on your way. To this day PHP.net is my best rescource for functions and general language questions. Now on this that your are doing now. I will suggest this. 1. Start with a login form, where the user will input the username and password. 2. Post it to the same page, and then run the query -> "SELECT FirstName,data FROM Members WHERE username='" . $_POST['username'] . "' AND password ='" . $_POST['password'] . '" LIMIT 1" Then once you have a result you can load all of the data into the session vars that you need. <?php $result = mysql_query("SELECT FirstName,data FROM Members WHERE username='" . $_POST['username'] . "' AND password ='" . $_POST['password'] . '" LIMIT 1"); if(!$result) { echo mysql_error(); } else { $row = mysql_fetch_array($result); $_SESSION['FirstName'] = $row['FirstName']; } ?> Now just to note this script is missing alot of stuff but you will be able to get the basic understanding I think... Let me know if you have any questions. and again Welcome to PHP! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.