Jiraiya Posted November 16, 2008 Share Posted November 16, 2008 i need help trying to display a users data on profile page I want to display only that users data like there username and stuff like there age Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/ Share on other sites More sharing options...
laPistola Posted November 16, 2008 Share Posted November 16, 2008 a bit more detail would help us help you Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691549 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 I want to display only a specific users information but having only one profile page that uses php to pull the specific users data from the database. but i want the php to pull only the information that belongs the the user who has logged in Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691551 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 If you are using SESSION variables to store the users log in data, in your sql statement just reference the username you would like to get the profile details for with the username that you have stored in the session Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691553 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 can you show me the script i would need to insert? im new to using php and msql and iv been teaching myself Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691554 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 are you using SESSION variables to store login details... how are you having users log in??  if you are using SESSIONS you will need soemthing like  <?php $username = $_SESSION['username']; //this is the session variable containing the username of the person logged in. $sql = mysql_query("SELECT [userdetails] FROM [tablename] WHERE username = '$username'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691557 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 it still dosent seem to be working ??? Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691562 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 copy and paste the code you are using for users to login and also the code you are using for displaying the profile.  or  post the web link if this is online for us to look at. Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691563 Share on other sites More sharing options...
AndyB Posted November 16, 2008 Share Posted November 16, 2008 A web link to the online version isn't really going to help. All it will show is the generated HTML. Â Also be specific as to what isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691568 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 the site is www.narutotalesofthesannin.com  login code    <?php // Connects to your Database mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error());  //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site']))  //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: player.php");  } } }  //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted  // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database  if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());  //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=http://narutotalesofthesannin.com/join.php>Click To Sign Up</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']);  //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else {  // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour);  //then redirect them to the members area header("Location: player.php"); } } } else {  // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?>  this is what i need and the code im using to show the profile information    <?php $username = $_SESSION['username']; //this is the session variable containing the username of the person logged in. $sql = mysql_query("SELECT [username] FROM [users] WHERE username = '$username'"); ?> <br> Level:? <br> Skill:? <br> Cash:? <br> Health:? <br> Chakra:? <br> Gender:? <br> Rank:? <br> Kills:? <br> Location:? <br> Village:? <br> Kekkei Genkai:? Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691570 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 please encase your code using the [ code ] tags, thats why they are there...  also i see that you are using cookies... so on your profile page, do some output echos and see what echoing '$username = $_COOKIE['ID_my_site'];' displays...  i have just skimmed the code so let me know what this code does  <?php echo $_COOKIE['ID_my_site']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691572 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 thank you that worked it displayed the username how would i change it so it displays the other information i want to display? Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691575 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 just change ur $username variable to the cookie variable...like below... Â <?php $username = $_COOKIE['ID_my_site'] //this is the session variable containing the username of the person logged in. $sql = mysql_query("SELECT [username] FROM [users] WHERE username = '$username'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691577 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 i dont quite get how to display the other variables ??? Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691579 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 just reference it to your users table, i assume in your members table you have fields such as  level skill cash health  etc   <?php $username = $_COOKIE['ID_my_site'] //this is the session variable containing the username of the person logged in. $sql = mysql_query("SELECT username,level,skill,cash,health FROM members WHERE username = '$username'"); while($row = mysql_fetch_array($sql)) {           echo $row['username']."<br/>";           echo $row['skill']."<br/>";           // Just keep going     } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691582 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 that still didnt work Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691587 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 there is no use saying "this didnt work"... what didnt work?? Â show us the table structure for your members table... we need to have a better understanding of how your database is setup and the tables that are inside it.. Â show us your database struucture and the fields in your members table.... Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691590 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 those are the variables   username varchar(30) latin1_swedish_ci  Yes NULL  Browse distinct values  Change  Drop  Primary  Unique  Index  Fulltext password varchar(32) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext skill mediumint(255) Yes 1500 Browse distinct values Change Drop Primary Unique Index Fulltext chakra mediumint(255) No 100 Browse distinct values Change Drop Primary Unique Index Fulltext rank varchar(255) latin1_swedish_ci No wannabe ninja Browse distinct values Change Drop Primary Unique Index Fulltext bloodline varchar(250) latin1_swedish_ci Yes unknown Browse distinct values Change Drop Primary Unique Index Fulltext kills longtext latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext level mediumint(255) Yes 1 Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691594 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 try this code  <?php $username = $_COOKIE['ID_my_site'] //this is the session variable containing the username of the person logged in. $sql = mysql_query("SELECT * FROM members WHERE username = '$username'");  while($row = mysql_fetch_array($sql)) {           echo $row['username']."<br/>";           echo $row['skill']."<br/>";           echo $row['chakra']."<br/>";           // Just keep going     } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691595 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 i added the code but the page comes up blank Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691596 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 turn on error_reporting and let me know if any errors are displayed... Â delete everything in the profile page and add the code below, upload and let me know if any errors come up. Â <?php error_reporting(E_ALL); // TURN ON ERROR REPORTING TO DISPLAY ALL ERRORS $username = $_COOKIE['ID_my_site'] //this is the session variable containing the username of the person logged in. $sql = mysql_query("SELECT * FROM members WHERE username = '$username'"); Â while($row = mysql_fetch_array($sql)) { Â Â Â Â Â Â Â Â Â Â echo $row['username']."<br/>"; Â Â Â Â Â Â Â Â Â Â echo $row['skill']."<br/>"; Â Â Â Â Â } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691600 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 i did what you said and it still came up blank Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691604 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 well i am looking at the page now and it is displaying fine for me  in your database, against the username 'tester' fill in all the other fields with numbers or text to see if they are displayed on the screen....  at this present moment, the page is showing correctly to me   Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691608 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 thats because i changed it back to its normal look after i tested that code you told me to use Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691611 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 k i added some variable random data Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/#findComment-691613 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.