我无法将其插入到数据库mysql中,但我认为我已经按照正确的方式进行了操作。有没有人知道如何解决?还是我错过了什么?实际上所有的工作。但它不会从我放入邮递员身上获得的价值
<?php
if (! isset($_POST['review'])) {
responJson(['success' => false, 'messege' => "'review' harus diisi"]);
exit;
}
if (! isset($_POST['rating'])) {
responJson(['success' => false, 'messege' => "'rating' harus diisi"]);
exit;
}
if (! isset($_POST['id_user'])) {
responJson(['success' => false, 'messege' => "'id_user' harus diisi"]);
exit;
}
if (! isset($_POST['id_movie'])) {
responJson(['success' => false, 'messege' => "'id_movie' harus diisi"]);
exit;
}
//bersihkan data
$review = mysqli_real_escape_string($connection, $_POST['review']);
$rating = mysqli_real_escape_string($connection, $_POST['rating']);
$user_id = mysqli_real_escape_string($connection, $_POST['id_user']);
$movie_id = mysqli_real_escape_string($connection, $_POST['id_movie']);
//masukkan data ke db
$query = mysqli_query($connection, 'INSERT INTO user_review (review, rating, id_user, id_movie)
values ("'. $review .'", "'. $rating .'", "'. $user_id .'", "'. $movie_id .'")');
//cek berhasil atau tidak dimasukkan db
if ($query) {
responJson(['success' => true, 'messege' => 'sukses memasukkan data']);
} else {
responJson(['success' => false, 'messege' => mysqli_error($connection)]);
}
答案 0 :(得分:1)
点击raw并从下拉列表中选择json(application / json),然后以json格式在正文中添加以下代码
{
"review": "bagus",
"rating": "3",
"id_user": "2",
"id_movie": "3"
}