Last active
July 26, 2017 19:22
PhP-Android-Mysql example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
$json = json_decode( file_get_contents('php://input') ); | |
$data= array(); | |
array_push($data,array('error'=>false)); | |
if (isset($json->{'username'}) && isset($json->{'password'}) && isset($json->{'password'})) { | |
$username = $json->{'username'}; | |
$password = $json->{'password'}; | |
$info_req = $json->{'info_req'}; | |
$con=mysqli_connect(/*Hidden from Public*/); | |
if (!$con) { | |
$data[0]["error"]=true; | |
array_push($data,array('message'=> 'Connection Failed. Bad Access to database!')); | |
} else { | |
$query="SELECT * FROM client_side_records WHERE username = '{$username}'"; | |
$result=mysqli_query($con,$query); | |
$row =mysqli_fetch_assoc($result); | |
$pass_db = $row["password"]; | |
if($pass_db==$password){ | |
if($info_req == "merchant_names"){ | |
$query="SELECT name, id FROM merchant_side_records"; | |
$result=mysqli_query($con,$query); | |
while($row=mysqli_fetch_assoc($result)){ | |
$temp = array('id'=>$row["id"],'name'=>$row["name"]); | |
array_push($data,$temp); | |
} | |
else{ | |
$data[0]["error"]=true; | |
array_push($data,array('message'=> 'Wrong Req!')); | |
} | |
} | |
} | |
} else { | |
$data[0]["error"]=true; | |
array_push($data,array('message'=> 'Login failed')); | |
} | |
} | |
} else { | |
$data[0]["error"]=true; | |
if(!isset($json['username'])){ | |
array_push($data,array('message'=> 'username not found...')); | |
} | |
else if(!isset($json['password'])){ | |
array_push($data,array('message'=> 'password not found...')); | |
} | |
else{ | |
array_push($data,array('message'=> 'info_req not found...')); | |
} | |
} | |
} else { | |
$data[0]["error"]=true; | |
array_push($data,array('message'=> 'Please check method. it must be POST')); | |
} | |
$response=array('tag'=>$data); | |
echo stripcslashes(json_encode($response, JSON_PRETTY_PRINT)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment