dr.maju Posted July 17, 2008 Share Posted July 17, 2008 Hey, i want to get and display the users login name on my members page. But i can't seem to get the data from the database. The data is in a database named Trinity_clients and in a table called members. Any help will be greatly appreciated thanks! <?php $dbh=mysql_connect ("localhost", "trinity_admin", "*MYPASSWORD*) or die('Cannot connect to the database because: ' . mysql_error()); mysql_select_db ("trinity_clients"); $id = ("GET * FROM `members` username"); echo $id; ?> Any help will be greatly appreciated thanks! Quote Link to comment https://forums.phpfreaks.com/topic/115279-solved-how-to-get-information-from-a-mysql-data-base-eg-show-user-login-information/ Share on other sites More sharing options...
wildteen88 Posted July 17, 2008 Share Posted July 17, 2008 You first need to readup on your MYSQL sytax. Use SELECT to retrieve data from a table. To run a query in PHP use the mysql_query function, followed by mysql_fetch_assoc You'll find helpful tutorials over at http://www.php-mysql-tutorial.com/ Quote Link to comment https://forums.phpfreaks.com/topic/115279-solved-how-to-get-information-from-a-mysql-data-base-eg-show-user-login-information/#findComment-592658 Share on other sites More sharing options...
p2grace Posted July 17, 2008 Share Posted July 17, 2008 you need to use mysql_query() to query a mysql database. You also need the members id from a variable such as a session var to display the login info. http://us2.php.net/manual/en/function.mysql-query.php <?php $query = "SELECT `username` FROM `members` WHERE `id` = '{$_SESSION['id']}'"; $run = mysql_query($query); if($run){ $arr = mysql_fetch_assoc($run); $id = $arr['id']; }else{ echo mysql_error(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115279-solved-how-to-get-information-from-a-mysql-data-base-eg-show-user-login-information/#findComment-592663 Share on other sites More sharing options...
dr.maju Posted July 17, 2008 Author Share Posted July 17, 2008 Hey, thanks for the replies. I have fixed the problem, thanks soooooo much for ure help! Quote Link to comment https://forums.phpfreaks.com/topic/115279-solved-how-to-get-information-from-a-mysql-data-base-eg-show-user-login-information/#findComment-592671 Share on other sites More sharing options...
p2grace Posted July 17, 2008 Share Posted July 17, 2008 Glad we could help, if you don't mind could you hit the "Topic Solved" button? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/115279-solved-how-to-get-information-from-a-mysql-data-base-eg-show-user-login-information/#findComment-592675 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.