PHP problem - greeting the user.

0 Jad Samadi · October 5, 2014
Hey there , i am a 14 years old boy who is still a bit new in PHP..I am trying to make a login and register system using PHP .
So far every thing worked perfectly and my site was able to register a user into my database and then letting him to login successfully .
Iv coded my site so far that when the user has successfully logged in the login form will be gone and replaced by a greeting message welcoming the user by his username.And this is where i have the problem .
My code is simply :



require '';
require '';

if (loggedin()) {
 echo 'Welcome <a href="logout.php">Log out</a>' ;
} else {
include '';




if (isset($_POST['username'])&&isset($_POST['password'])) {
  $username = $_POST['username'];
  $password = $_POST['password'];

  $password_hash = md5($password);

  if (!empty($username)&&!empty($password)) {

    $query = "SELECT `id` FROM `users` WHERE `username`='$username' AND `password`='$password_hash'";
    if ($query_run = mysql_query ($query)) {
     $query_num_rows = mysql_num_rows($query_run);

     if ($query_num_rows==0) {
        echo 'Invalid username and password combination';
     } else if($query_num_rows==1){
       $user_id = mysql_result($query_run, 0, 'id');
       $_SESSION['user_id'] =$user_id;
       header('Location: index.php');


  } else {
    echo 'You must supply a username and a password';


<form action="<?php echo $current_file; ?>" method="POST">
UserName: <input type="text" name="username"> Password: <input type="password" name="password">
 <input type="submit" value="Log in">

as you can see in index.php it say :

if (loggedin()) {

 echo 'Welcome <a href="logout.php">Log out</a>' ;

i want to insert after the world  '  Welcome ' the username for example :
Welcome Jad . Log out (this is what the index.php should display)
instead it shows : Welcome . Log out.
I tried variety of codes to add the username but i have failed. If you can help me i would be thankful .
Thanks for reading ,

Post a Reply


Oldest  Newest  Rating
0 Jad Samadi · October 5, 2014
yes thanks for your support .
I did include in the following files :


and this is the current code :



$current_file = $_SERVER['SCRIPT_NAME'];
$http_referer = $_SERVER['HTTP_REFERER'];

function loggedin() {
 if (isset($_SESSION['user_id'])&&!empty($_SESSION['user_id'])) {
 return true;
 } else {
 return false;

so like what should i do?
0 Jad Samadi · October 5, 2014
alright i found the solution ... thanks for your support any way :)
0 Susan Moss · November 10, 2014
Can you share with us the code for the solution you've arrived to? That would be great! :D
-1 Godspower Onedo · October 6, 2014
Am happy u find ur solution jad, #goodluck.
  • 1



Server-side, HTML embedded scripting language used to create dynamic Web pages.