I can't figure out why my php script always returns NULL. I'm developing an Android app that gets user data from a database via a PHP script that returns JSON data. The app parses the data, but I can't get the PHP script to return anything other than NULL. The app uses JSON data for both the data returned for the user, and the result
, which is either 1 or 0. I'm still new to PHP, so I'm a bit confused.
Here's my PHP script:
<?php
define('HOST','localhost');
define('USER','user');
define('PASS','password');
define('DB','database');
if (!empty($_POST)){
if (empty($_POST['userID'])){
$response["success"] = 0;
$response["message"] = "Please enter a User ID";
die(json_encode($response));
}
$userID = mysql_escape_string($_POST['userID']);
$con = mysqli_connect(HOST,USER,PASS,DB);
$result = mysql_query("SELECT* FROM users WHERE id = $userID");
if ($result && mysql_num_rows($result) > 0){
$response["result"] = array();
while($row = mysql_fetch_array($result)){
$finduser = array();
$finduser["id"] = $row["id"];
$finduser["firstname"] = $row["firstname"];
$finduser["company"] = $row["company"];
$finduser["position"] = $row["position"];
array_push($response["result"], $finduser);
}
$response["success"] = 1;
}
echo json_encode($response);
} else {
?>
<h1>Search by User ID:</h1>
<form action="searchbyuserid.php" method="post">
Enter the UserID of the receipient:<br />
<input type="text" name="userID" placeholder="User ID" />
<br /><br />
<input type="submit" value="Submit" />
</form>
<a href="register.php">Register</a>
<?php
}
?>