2

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.

4
  • 1
    You realize you spelled 'connect' wrong, right? Commented Sep 30, 2012 at 22:14
  • 1
    Try var_dump($_POST) and see what comes up. Commented Sep 30, 2012 at 22:14
  • 1
    This is likely a typo $_POST['saveConection'] should be $_POST['saveConnection'] unless misspelled in your form too... Commented Sep 30, 2012 at 22:17
  • 1
    Is 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 check if (isset($_POST['saveConection'])) Commented Sep 30, 2012 at 22:19

1 Answer 1

4

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 !

Sign up to request clarification or add additional context in comments.

1 Comment

I know that they are existing because I posted the via ajax call

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.