我已经从网上下载了这个脚本以获取数据。我在我的java代码中使用这些数据。事实是,我没有任何PHP经验,所以请不要低估这个问题。我无法找出这个脚本中的问题PHP脚本返回数据
这就是这个PHP脚本返回并导致java中的JsonExceptions。
07-15 14:18:46.725: I/System.out(1799): displaying <br /><b>Parse error</b>:
syntax error, unexpected end of file in <b>C:\xampp\htdocs\xmytestdb\login.php</b>
on line <b>64</b><br />
此脚本导致问题,因为它不从数据库返回适当的json格式数据。
<?php
require("config.inc.php");
if (!empty($_POST)) {
$query = "
SELECT
id,
username,
password
FROM usernamepass
WHERE
username = :username
";
$query_params = array(
':username' => $_POST['username']
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error1. Please Try Again!";
die(json_encode($response));
}
$validated_info = false;
$row = $stmt->fetch();
if ($row) {
if ($_POST['password'] === $row['password']) {
$login_ok = true;
}
}
if ($login_ok) {
$response["success"] = 1;
$response["message"] = "Login successful!";
die(json_encode($response));
} else {
$response["success"] = 0;
$response["message"] = "Invalid Credentials!";
die(json_encode($response));
}
} else {
?>
我将非常感谢您的宝贵帮助。
我试过,但比不返回任何东西。它返回空字符串。 –