Thursday, November 26, 2015

PHP Login web service | PHP code for login | PHP Simple webservices

//take the values from client as json
$json = file_get_contents('php://input');
//open database connection
$con = mysql_connect('localhost','root','root') or die('Cannot connect to the DB');
//take json values into data variable
$data = json_decode($json);

//make a sql query to store data
$sql="SELECT * from `mydb`.`user` WHERE email = '".$data->{'email'}."' AND password = '".$data->{'password'}."'";

//check the database response it is true or false
 if (mysql_num_rows($qur)>= 1 ) {
$json=array("status"=>0,"message"=>"email or password not match!");
//close the database connection
//set header
header('Content-type: application/json');
//print the result as json object
echo json_encode($json);
widgets for blogger