我正在尝试使用我的Android应用程序执行CRUD操作。 显然JSON & PHP是做到这一点的方式,但我只找到似乎过时的示例(Android Studio将大多数对象标记为不赞成使用)。 现在我没有得到任何工作,但这可能是因为我的PHP。从Javascript发送数据到JSON PHP服务
无论如何:有人能告诉我一个关于如何将数据从我的Android应用程序发布到我的JSON服务的最新示例吗?
下面是我的INSERT语句的PHP(这是我从2个教程拼凑起来):
include 'dbconn.php';
$get = json_decode(stripslashes($_POST['req']));
$userID = $get->userID;
$text = $get->text;
$erstellt = $get->erstellt;
$sql = "INSERT INTO 4188647db4.status (id, userID, text, erstellt) VALUES (NULL, '$userID', '$text', '$erstellt');";
if ($connection->query($sql)) {
$msg = array("status" =>1 , "msg" => "OK");
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($connection);
}
$json = $msg;
header('content-type: application/json');
echo json_encode($json);
@mysqli_close($conn);
谢谢,这似乎工作的Java部分。不过,我仍然无法在PHP中获得POST数据。我试过$ get = json_decode(file_get_contents('php:// input'));但它也不起作用。 – PectoralisMajor