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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.