Hi, I need some help in this session,why i could not get the name or put some session when the user login...but i can successfully login and when i tried to echo the user it is empty...can you please help me on this.


This is my code.

Loginform.php //I use ajax in requesting

Code:
    $(function(){
           $('#btn').click(function(e){
               e.preventDefault();
               var serializeform = $('#myform').serialize();
               $.ajax({
                   type: 'post',
                   url: 'tologin.php',
                   data: serializeform,
                   success: function(data){
                       if(data == 'success'){
                           window.location.href = 'success.php';
                       }
                      

                   }
               });

           });
       });
PHP Code:
  <?php
    
include_once('connection.php');

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


           
$messageuserlogin($username,$password);

           echo 
$message;
    }

?>
connection.php

Code:
  function userlogin($username,$password)
{
    try {
       .....................
       ......................
       ......................

      select statement here
       .............................................
       .........................................


        if ($cm->rowCount() == 1) {

            $row=$cm->fetch(PDO::FETCH_OBJ);

            $_SESSION['username']=$row->username;
            $_SESSION['password']=$row->password;

            return "success";
        }
     
    } catch (PDOException $exception) {
        return "Failed"
    }
}

success.php

PHP Code:
    session_start();
    
$user='';
      if(isset(
$_SESSION['username'])){
          
$user $_SESSION['username'];
      }

    echo 
"user"
user is empty i don't know why.


Please help me Thank you in avdvance.