How to return an error message when connecting to my sql database useing jquery post
I am trying to return an error using jquery post function to retrieve the error.
So far I have开发者_如何学编程 written in php
$connect = mysql_connect("localhost","username","password") or die("Error connecting to the database.");
but i want to retunrn the message like so
$connect = mysql_connect("localhost","username","password");
if(!$connect){
$data['error'] = true;
$data['message'] = "Error connecting to the database.";
echo json_encode($data);
};
Help!!
Try this:
$connect = mysql_connect("localhost","username","password") or die(json_encode(array('error' => true, 'message' => mysql_error())));
This will encode the error to a json string
精彩评论