Below is my config.php
<?php
const server = "localhost";
const dbuser = "root";
const dbpw = "";
const db = "mp19_tca";
?>
Here below is my login.php
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
header("Content-Type: application/json; charset=UTF-8");
error_reporting(E_ERROR);
//tells login.php the username/password and name to the database
include("config.php");
try{
$found = 0;
$conn = new mysqli(server, dbuser, dbpw, db);
//login accepts a userid and password from the caller
$userid = $_GET["user_id"];
$password = $_GET["password"];
//it then runs an SQL statement to check the database if this record exist
$query = "SELECT email FROM usermobile WHERE user_id ='" . $userid . "' and password = '" .
$password . "'";
$result = $conn->query($query);
$outp = "[";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {
$outp .= ",";
}
$outp .= '{"result":"' . $rs["email"] . '"}';
$found = 1;
}
if ($found == 0){
$outp .= '{"result":"0"}';
}
$outp .="]";
echo $outp;
$conn->close();
}
catch(Exception $e) {
$json_out = "[".json_encode(array("result"=>0))."]";
echo $json_out;
}
?>
I have added data into my MySQL data, but when i run these codes my results turned out 0. The purpose of using this PHP codes is to create a login page to communicate with the database my Cordova app, using jQueryMobile. So am wondering where did i go wrong? Is the result output supposed to be email?
Results of data