sean14592 Posted March 28, 2008 Share Posted March 28, 2008 Hi, I have a login system and I once the user is logged in they are taken to there user Cpanel. What I want to do is to be able to say "Welcome [Full Name], Enjoy your stay!", When the users register they have to save there full name in the database, so I just need to know how to extract this and print it to screen. Cheers Sean Preston Link to comment https://forums.phpfreaks.com/topic/98403-grab-informatin-from-database/ Share on other sites More sharing options...
BlueSkyIS Posted March 28, 2008 Share Posted March 28, 2008 can we see the code you've got so far? that will at least let us know what kind of database you're using. Link to comment https://forums.phpfreaks.com/topic/98403-grab-informatin-from-database/#findComment-503564 Share on other sites More sharing options...
frijole Posted March 28, 2008 Share Posted March 28, 2008 that is a pretty basic query of the database but it sounds like you might need to brush up on some of the basics of PHP and MySQL. php.net has all the information you will need about PHP. You will need to use PHP to query your database, with the mysql_query() function. Inside of the parenthesis will go the instructions for MySQL that will tell it to find you the username of this particular user. The MySQL query will be formed something like: SELECT username FROM members WHERE userid = $_SESSION['userid'] Basically you will need to learn a little bit to do it. But, it is one of the easiest possible scripts to write. Link to comment https://forums.phpfreaks.com/topic/98403-grab-informatin-from-database/#findComment-503568 Share on other sites More sharing options...
ohdang888 Posted March 28, 2008 Share Posted March 28, 2008 ya lets see the code. Link to comment https://forums.phpfreaks.com/topic/98403-grab-informatin-from-database/#findComment-503585 Share on other sites More sharing options...
sean14592 Posted March 28, 2008 Author Share Posted March 28, 2008 $connect = mysql_connect($host,$username,$password) or die("Error connecting to Database!". mysql_error()); mysql_select_db($database,$connect) or die("cannot select database!".mysql_error()); //Check if username exists $fetchname = mysql_query("SELECT name FROM users WHERE username=$_SESSION['username']") or die(mysql_error()); $a_record = mysql_fetch_array($fetchname); $namereturn = $a_record['name']; echo("Welcome".$namereturn. ",hi"); the database info is included in a config.php which is included in this file at the very top! Cheers Sean Link to comment https://forums.phpfreaks.com/topic/98403-grab-informatin-from-database/#findComment-503586 Share on other sites More sharing options...
BlueSkyIS Posted March 28, 2008 Share Posted March 28, 2008 correction: $fetchname = mysql_query("SELECT name FROM users WHERE username='{$_SESSION['username']}'") or die(mysql_error()); explanation: $_SESSION is an array, so like any array you need to add curly brackets around it when used as you have in a double-quoted string. you should also always single-quote values. Link to comment https://forums.phpfreaks.com/topic/98403-grab-informatin-from-database/#findComment-503608 Share on other sites More sharing options...
sean14592 Posted March 28, 2008 Author Share Posted March 28, 2008 awsome, cheers, you guys are sooooo good. Thanks loads! Link to comment https://forums.phpfreaks.com/topic/98403-grab-informatin-from-database/#findComment-503618 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.