Reputation: 9295
I have aproblem with a AJAX POST via jQuery. Here is the client code:
$.ajax({
url: 'php/registration_and_login/login.php',
type: 'post',
data: {saveConection: saveConection, loginEmail: loginEmail, loginPass: loginPass }
}).always(login);
And here is the PHP code:
<?php
include '../functions/connection.php';
$link = conenct('localhost', 'root', '', 'w_db');
$saveConection = $_POST['saveConection'];
$loginEmail = $_POST['loginEmail'];
$loginPass = $_POST['loginPass'];
$loginEmail = mysql_real_escape_string($loginEmail);
$loginPass = mysql_real_escape_string($loginPass);
$saveConection = mysql_real_escape_string($saveConection);
$emailResult = mysql_query("SELECT COUNT('id') FROM users WHERE userEmail = '$loginEmail' AND userPass = '$loginPass'") or die('Invalid query:'. mysql_error());
$validation = mysql_result($emailResult, 0);
if($validation) {
$query1 = mysql_query("SELECT id FROM users WHERE userEmail = '$loginEmail'") or die('Invalid query:'. mysql_error());
$tmp = mysql_fetch_assoc($query1);
$id = $tmp['id'];
session_start();
$_SESSION['id'] = $id;
if($saveConection == 'yes'){
setcookie('login', $loginEmail);
setcookie('password', $loginEmail);
}
echo "true";
}
else {
echo "false";
}
?>
I am getting this error:
Notice: Undefined index: saveConection in C:...\login.php on line 5
It seems to me that there is no problem with the POST of saveConection
, and I can't find the problem.
Upvotes: 2
Views: 780
Reputation: 66
for your post value you must check if they are existing before calling the page ...
so you must do :
if(isset($_POST['saveConection']))
$saveConection = $_POST['saveConection'];
if(isset($_POST['loginEmail']))
$loginEmail = $_POST['loginEmail'];
if(isset($_POST['loginPass']))
$loginPass = $_POST['loginPass'];
i hope you understand !
Upvotes: 4