jeudi 30 juin 2016

Pass variable from another page

I can't pass the variable to another page using session and i don't know what is the error here. Can someone help me? and clues on how to use the session? i want to pass the variable username to another page.

here is the html code. this is my login page where the variable is coming from.

  <div class="wrapper">
  <form class="logform" action="" method="post">
    <p class="title">Admin Login</p>
    <input type="user" name="uname" placeholder="Username" autofocus/>
    <i class="fa fa-user"></i>
    <input type="password" name ="pword" placeholder="Password" />
    <i class="fa fa-key"></i>
    <a href="#">Forgot your password?</a>
    <button type="submit" value="login" name="login">
      <i class="spinner"></i>
      <span class="state">Log in</span>
    </button>
  </form>
</div>

<?php
session_start();

include_once("connection.php");
if(isset($_POST['login'])){
    $user = $_POST["uname"];
  $password = $_POST["pword"];
    $name = mysqli_real_escape_string($con, $user);
    $password = mysqli_real_escape_string($con, $password);
    $select_user="SELECT * FROM accounts WHERE username ='$user' AND password ='$password'";
    $run_user = mysqli_query($con, $select_user);
    $check_user = mysqli_num_rows($run_user);
    if($check_user > 0){
    $_SESSION['uname'] = $username;
        header('location:admin.php');
    }
    else{
        echo "wrong";
    }
}
?>

here is the admin page.

<?php
session_start();
?>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>

    <h1>Welcome, <?php echo $username; ?>!</h1>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire