简体   繁体   中英

can't insert in database mysql

I cannot insert it to my database mysql but I think I already did it the right way. is there anyone know how to solve it? or I missed something?. it actually all work. but it won't take the value from body that I put in postman

邮寄

    <?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)]);
}

Click raw and select json(application/json) from dropdown and add following code in body in json format

{
  "review": "bagus",
  "rating": "3",
  "id_user": "2",
  "id_movie": "3"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM