-1

I have a password reset PHP form page that has another PHP file in action attribute of form tag. the latter (say process.php) processes the formers(say reset.php) form data to reset the password in the database now in between these two I have used a js file for client-side form validation and sending $.post request

in the data attribute of $.post request i inserted the $data = $("#passwordresetform :input").serializeArray();

until this point, every thing works fine when I see form data in developer tool for process.php page it shows the data as required but I have received the data in process.php using

mysql_real_escape_string(trim($_POST['email']));

and stored all values in the associative array as

$data = array (
    'name' => $username,
    'email' => $email,
    'password' => $pass,
); 

to return the data I have used

echo json_encode($data);

but it not returning data back e.g when I seeing preview section of developer tool it shows false for every key in returned data object i.e data

how do I solve this problem? thanks in advance.

I think the problem is really with my database connection as after I removed mysql_real_escape_string(trim( it worked fine so is there any other way to sanitize $_POST data?

but had it been a database connection problem then how come the same page retrieves data from database?

Roham Rafii
  • 2,929
  • 7
  • 35
  • 49
ashsam786
  • 143
  • 1
  • 6

2 Answers2

1

mysql_real_escape_string() - Returns the escaped string, or FALSE on error.

further: A MySQL connection is required before using mysql_real_escape_string() otherwise an error of level E_WARNING is generated, and FALSE is returned. If link_identifier isn't defined, the last MySQL connection is used.

see: http://www.php.net/manual/en/function.mysql-real-escape-string.php

Manuel Richarz
  • 1,916
  • 13
  • 27
  • i have used database connection – ashsam786 Apr 15 '14 at 07:04
  • have you tried to remove all the stuff, like mysql_real_escape_string() and other functions like trim and whatever, that is not really needed to get any result other than false? – Manuel Richarz Apr 15 '14 at 07:10
  • is it so? and you are sure you have a mysql-connection opened? try to select something from your mysql directly under your mysql_real_escape_string() – Manuel Richarz Apr 15 '14 at 07:34
0

You will need to assign values to varibales $username, $email and $pass.

$data = array (
    'name' => $username,
    'email' => $email,
    'password' => $pass,
); 
Sankalp Bhatt
  • 1,154
  • 13
  • 17
  • Are you successfully connected to mysql database as mysql_real_escape_string() returns FALSE when database connected link does not exists. – Sankalp Bhatt Apr 15 '14 at 11:11