Thursday, November 26, 2015

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



<?php
//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');
mysql_select_db('mydb',$con);
//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'}."'";
$qur=mysql_query($sql);

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

No comments :

Post a Comment

Note: Only a member of this blog may post a comment.