Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    redirect with message in case of failed login

    Hi All

    I am newbie in php and I want trying to make login application and I came to below issue:

    1. In case of failed login how to redirect user in same page with meg like username and password do not match.
    At this moment I have used header function but it simply redirect to my index.php(which is in fact login page)....but I want it with message....

    Thanks
    PHP Code:
    if(isset($_POST['uname']) && isset($_POST['passwd']))
    {

     
    $usrname $_POST['uname']; 
     
    $passwd $_POST['passwd'];
     
    $pass_haas =($passwd);
        if(!empty (
    $usrname) && !empty($passwd))
        {
            
    $query "SELECT * FROM `user_info` WHERE `uname` = '$usrname' AND `passwd` = '$pass_haas' ";
            
            
            
    $query_run mysql_query($query);
            
                
            
    $query_num_rws mysql_num_rows($query_run);
                
                
                
                if(
    $query_num_rws == Null)
                {
                    
                    
    header('Location:login.php');
                    
                }
                else if (
    $query_num_rws == 1)
                {
                    
    $user_id mysql_fetch_assoc($query_run);
                    
                     
    $user_name $user_id['g_name'];
                    
                    
                    
    $_SESSION['g_name'] = $user_name;
        
                
                    
    header('Location:welcome.php');
                
                }
                
        }        
        else
        {
            echo 
    'You must supply user name and Password';
        }


  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    at the top of the login page you can put smething like


    if(isset($_GET['failed'])) { if($_GET['failed'] == 1) { echo "Your login failed."; } }

    then change the header to header('location:login.php?failed=1');

  • #3
    New Coder
    Join Date
    May 2011
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you..It works


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •