lundi 7 avril 2014

formules - Page de requête de connexion Ajax - Stack Overflow


I have 2 Logins. One is within the navigation and is working flawless. One is on my "no permission page" and i copied the ajax code and the form, changed some stuff but there is no chance i got it working. dont know why.


What the code does at the moment: NOTHING. Ajax is not working at ALL. (only with this login form). My site redirects my to login.php (i do not stay at same page). Also on login.php the "echo false" triggers.


My Login Form:


<form action="<?php echo get_option("home"); ?>/sys/login.php" method="POST">
<input type="hidden" value="1" name="permission_cookie" id="permission_cookie">
<input type="text" value="" name="permission_name" class="permission_input" id="permission_name">
<input type="password" value="" name="permission_pw" class="permission_input" id="permission_pw">
<input type="submit" id="permission_submit" value="" />
<div id="permission_error"></div>
</form>

My AXAX Code:


$(document).ready(function(){
//AJAX PERMISSION LOGIN
$("#permission_submit").click(function(){
alert('Name: '.permission_name.'\nPW: '.permission_pw);
permission_name=$("#permission_name").val();
permission_pw=$("#permission_pw").val();
permission_cookie=$("#permission_cookie").val();

$.ajax({
type: "POST",
url: "http://www.mylui.org/sys/login.php",
data: {
name: permission_name,
pwd: permission_pw,
rememberme: permission_cookie
},
success: function(html){
if(html=='true') {
do some stuff
} else if(html=='new') {
do some stuff
} else {
$("#permission_error").fadeIn().delay('4000').fadeOut();
}
},
});
return false;
});

});


My PHP Code:


session_start();

$rememberme = safe($_POST['rememberme']);
$username = safe($_POST["name"]);
$password = safe($_POST["pwd"]);
$password = md5($password);

if($con == false){
include($_SERVER['DOCUMENT_ROOT'].'sys/dbconn.php');
}

$query = "SELECT * FROM users WHERE name = '".$username."' AND pw = '".$password."'";
$result_user = mysqli_query($con,$query);

$num_row = mysqli_num_rows($result_user);
$row = mysqli_fetch_array($result_user);

if( $num_row >= 1 ) {
$_SESSION['user_name'] = $row['name'];
$_SESSION['user_id'] = $row['uid'];

echo 'true';
} else {
echo 'false';
}

Hopefully someone of you can help me. much appreciated!!!



I have 2 Logins. One is within the navigation and is working flawless. One is on my "no permission page" and i copied the ajax code and the form, changed some stuff but there is no chance i got it working. dont know why.


What the code does at the moment: NOTHING. Ajax is not working at ALL. (only with this login form). My site redirects my to login.php (i do not stay at same page). Also on login.php the "echo false" triggers.


My Login Form:


<form action="<?php echo get_option("home"); ?>/sys/login.php" method="POST">
<input type="hidden" value="1" name="permission_cookie" id="permission_cookie">
<input type="text" value="" name="permission_name" class="permission_input" id="permission_name">
<input type="password" value="" name="permission_pw" class="permission_input" id="permission_pw">
<input type="submit" id="permission_submit" value="" />
<div id="permission_error"></div>
</form>

My AXAX Code:


$(document).ready(function(){
//AJAX PERMISSION LOGIN
$("#permission_submit").click(function(){
alert('Name: '.permission_name.'\nPW: '.permission_pw);
permission_name=$("#permission_name").val();
permission_pw=$("#permission_pw").val();
permission_cookie=$("#permission_cookie").val();

$.ajax({
type: "POST",
url: "http://www.mylui.org/sys/login.php",
data: {
name: permission_name,
pwd: permission_pw,
rememberme: permission_cookie
},
success: function(html){
if(html=='true') {
do some stuff
} else if(html=='new') {
do some stuff
} else {
$("#permission_error").fadeIn().delay('4000').fadeOut();
}
},
});
return false;
});

});


My PHP Code:


session_start();

$rememberme = safe($_POST['rememberme']);
$username = safe($_POST["name"]);
$password = safe($_POST["pwd"]);
$password = md5($password);

if($con == false){
include($_SERVER['DOCUMENT_ROOT'].'sys/dbconn.php');
}

$query = "SELECT * FROM users WHERE name = '".$username."' AND pw = '".$password."'";
$result_user = mysqli_query($con,$query);

$num_row = mysqli_num_rows($result_user);
$row = mysqli_fetch_array($result_user);

if( $num_row >= 1 ) {
$_SESSION['user_name'] = $row['name'];
$_SESSION['user_id'] = $row['uid'];

echo 'true';
} else {
echo 'false';
}

Hopefully someone of you can help me. much appreciated!!!


0 commentaires:

Enregistrer un commentaire