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.
var_dump($_POST)and see what comes up.$_POST['saveConection']should be$_POST['saveConnection']unless misspelled in your form too...saveConection(if spelled that way) a checkbox? If it is, the post key won't be present unless it is checked. So if you submit it without checking the box, it will issue the notice. Instead checkif (isset($_POST['saveConection']))