www.webdeveloper.com
Results 1 to 3 of 3

Thread: Redirect after login doesn't work

Threaded View

  1. #1
    Join Date
    Jan 2013
    Posts
    84

    Unhappy Redirect after login doesn't work

    Hi
    for what reason this code doesn't work?

    PHP Code:
    <?php

    $f_usr
    $_POST["username"];
    $f_pswd$_POST["password"];

    $con=mysql_connect("localhost","americanhorizon","")
    or die(
    "Unable to connect to MySQL");


    //select a database to work with
    $selected mysql_select_db("my_americanhorizon",$con)
      or die(
    "Could not select my_americanhorizon");

    $sql="SELECT * FROM negozi WHERE Username='$f_usr'";
    $result=mysql_query($sql,$con);


    $datiUtente=mysql_fetch_assoc($result);

    if(
    $datiUtente==array()) // if empty array
    {
      echo(
    "Sorry");
    }
    else
    {
       
    //$_SESSION['datiUtente']=$datiUtente;
       
    header("Location: userPanel.php"); //successfully logged
    }

    mysql_close($con);

    ?>
    in the php page that contains the form, the "Sorry" response is correctly processed, while header("Location: userPanel.php"); for redirect the page to the userpanel if successfully logged doesn't work


    This is the form page (it's not necessary that you read it, it's should be correct. Only one doubt, i wrote the condition "if (ajaxReq.responseText == "Sorry")"... Maybe i've to write a condition in case of redirection too?)

    HTML Code:
     <div id="logindAndRegistra">
         <div id="sezionesx">
           <div class="scritta" id="loginHeader">Login</div><br />
           <div class="scritta">eMail <br /><input id="username"/></div><br />
           <div class="scritta">Password <br /><input id="password"/></div><br />
           <button id="loginVai">Vai -></button>
           
         </div>
    
    <script>
    $('#loginVai').click( function() 
    					 {
    						 var ajaxReq = new XMLHttpRequest();
    						 
    						 var params = "username="+$('#username').val()+"&password="+$('#password').val();
    						 var url = "tentaLogin.php";
    						 ajaxReq.open("POST", url, true);
    						 
    						 ajaxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    						 ajaxReq.setRequestHeader("Content-length", params.length);
    						 ajaxReq.setRequestHeader("Connection", "close");
    
    						 ajaxReq.onreadystatechange = function() 
    													  {
    														
    														  if(ajaxReq.readyState == 4 && ajaxReq.status == 200) 
    														  {
    															  alert(ajaxReq.responseText)
    															  if (ajaxReq.responseText == "Sorry")
    															  {
    																  $("#loginSbagliato").remove(); 
    																  $('#sezionesx').append($('<div id="loginSbagliato" class="baloon up scritta">I dati inseriti sono errati</div>'))
    															      $('#loginSbagliato').hide();
    																  $('#loginSbagliato').show(400);
    															  }
    															  
    																												  
    														  }
    													   }
    						  
    						  ajaxReq.send(params);
    				   
    					 }
    				   
    				   )
    Last edited by American horizo; 04-14-2013 at 08:30 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles