0

login code

<?php  
include("koneksi.php");

$email=$_POST['email'];
$password=md5($_POST['password']);

$q="SELECT * FROM `user` WHERE `user`.`email`='$email' AND `user`.`password`='$password'";
$qe=mysql_query($q);

while ($de=mysql_fetch_array($qe)) {
    $id_user=$de['id_user'];
}
if (mysql_num_rows($qe)>0) {
    session_start();
    $_SESSION['x']=$id_users;

    header('location:home.php');
    exit;
} else{
    header('location:login_user.php');
    exit;
}

?>

after login i wanna show or echo the username with this code

<?php  
session_start();
$id_user=$_SESSION['x'];

$q="SELECT * FROM `user` WHERE `user`.`id_user`='$id_user'";
$qe=mysql_query($q);
$de=mysql_fetch_array($qe);
    $username=$de['username'];
    echo "
        <li><a href=\"\">$username</a></li>
    ";

?>

and the problem is the username doesn't show.. whats wrong.. help me ..

nerdy
  • 11
  • 4

1 Answers1

0

You have a typo in your login search query. Change to $_SESSION['x'] = $id_user;

Not $id_users

A piece of advice, use an IDE such as netbeans or eclipse or phpstorm. They help in identifying unused variables and other minor syntax errors.

Rotimi
  • 4,783
  • 4
  • 18
  • 27