I want to insert data into database with ajax and I got message in console that it does work also no errors but the data is not inserting into database.
Php code:
<?php
include 'connection.php';
if($_POST['action'] == 'rating')
{
echo "work";
$user_name = $_POST['user_name'];
$rating_index = $_POST['rating_index'];
$user_review = $_POST['user_review'];
$stmt = $conn->prepare("INSERT INTO review_table
(review_id, user_name, user_rating, user_review, datetime)
VALUES (NULL, ?, ?, ?, NOW())");
$stmt->bind_param('sis', $user_name, $user_rating, $user_review);
$stmt->execute();
}
?>
and like I said I have echo “work” printed in console so it is connecting with ajax and also I checked if variable are set correctly and they are.
ajax code:
$.ajax({
url:"rating-data.php",
method:"POST",
data: {
action:'rating',
rating_index: rating_index,
user_name: user_name,
user_review : user_review
},
success:function(data)
{
$('#review_modal').modal('hide');
// load_rating_data();
console.log(data);
}
})