Jump to content

trouble pulling name from database


Bobbycarver

Recommended Posts

Hi. im new to the site and i need a bit of help. im coding a website for my coursework and ive created a log in script.

 

the script works but once the user has logged in i want to get a message saying welcome "firstname" instead of welcome "username"

 

i have managed to get it to say welcome and there username but its not very formal i would like there name they use when they register.

 

here is the code ive got so far. any help would be greatly appriciated.

 

<?php
 session_start();
$user_name = "root";
$password = "";
$database = "fixandrun";
$server = "localhost";



$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

$username = $_POST["username"];
$password = $_POST["password"];

echo"$password";
echo"$username";


if ($db_found) {
$result =mysql_query("SELECT 1 FROM staff WHERE username= '$username' and password= '$password'");
if ($result && mysql_num_rows($result) == 1)

    {
	     
		 $sqlq = mysql_query("SELECT firstname FROM staff WHERE username = '$username'");
		 $_SESSION['name']=$sqlq;
        session_register("username");
         header("location:homelogged.php");
    }
else
    {
	    
	Echo "Username or Password is incorrect. Click <a href='home.php'>Here</a> to be taken back to the home page.";
    }
}
else {
print "Database NOT Found.";
mysql_close($db_handle);
}
 ?>


and on my home page i have :

<?php
						      
                             echo "Welcome " . $_SESSION["name"] . "<br>";
							 echo "last logged in at " .  date("l, F d,  h:i" ,time())."<br>"; 
                          ?>

this works but i get welcome and 0 instead of welcome and a name

Link to comment
https://forums.phpfreaks.com/topic/275671-trouble-pulling-name-from-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.