I linked my database to 000webhost
it connected successfully but i keep getting this error
the php file :
<?php
include('database2.php');
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
$conn = mysqli_connect($dbserver, $user, $pass, $db);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
//THE ERROR IS HERE
$request = json_decode($postdata);
$username = $request->username;
$userpass = $request->userpass;
$sql = sprintf("SELECT * FROM account_info where a_username='%s' ",
//WHERE User_Name='%s' AND User_Pass='%s'
mysqli_real_escape_string($conn,$username),
mysqli_real_escape_string($conn,$userpass));
$result=$conn->query($sql);
if ($result->num_rows>0)
{ $UserID=0;
while($row=$result->fetch_assoc())
{$UserID=$row["acc_id"];
}
$myobj=array();
array_push($myobj,array('isloggedin'=>'true','userid'=>$UserID));
echo json_encode($myobj);
}
else
{
$myobj=array();
array_push($myobj,array('isloggedin'=>'false'));
echo json_encode($myobj);
}
}
?>
when i test it on my phone i get the alert this.showAlert('Something Went Wrong!');
error unexpected token in json at position 0