Hi
for what reason this code doesn't work?
<?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?)
<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);
}
)