I have question regarding on my Inserting Module, Why does the response shows Internal Server Error 500 ? Is the front end side has a problem? It means something has gone wrong on the website? But I tried on my updating content module the ajax is working. however in my inserting module, the ajax gives the error. why does it happen? could someone can help me about this problem? thank you.
Front End Ajax:
$(document).ready(function(){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
const email = localStorage.getItem('email');
$('#hidden_auth_user').val(email);
$('.about_psmid_button').on('click',function(){
const about_psmid_page = $('#about_psmid_page').val();
const about_psmid_title = $('#about_psmid_title').val();
//const about_psmid_content = $('#about_psmid_content').val();
const hidden_auth_user = $('#hidden_auth_user').val();
const ck_editor_content = CKEDITOR.instances['about_psmid_content'].getData();
const data = new FormData();
data.append('about_psmid_page',about_psmid_page);
data.append('about_psmid_title',about_psmid_title);
data.append('about_psmid_content',ck_editor_content);
data.append('hidden_auth_user',hidden_auth_user);
Swal.fire({
title: 'Are you sure to add this content?',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#008B74',
confirmButtonText: 'Okay'
}).then((result) => {
if (result.value) {
$.ajax({
url:'./Function/aboutPMSIDAddFunction.php',
data:data,
type:'POST',
dataType:'JSON',
processData: false,
contentType: false,
success:function(response){
Swal.fire(
'Success!',
'Data information has been saved.',
'success'
)
if(response == 'Successfully Inserted') {
location.reload();
}
},
error:function(response) {
console.log(response);
}
});
}
})
});
});
Back End Php:
<?php
require_once('../ConnectionString/require_db.php');
session_start();
//submit function
if(isset($_POST['about_psmid_page']))
{
$about_psmid_page = $_POST['about_psmid_page'];
$about_psmid_title = $_POST['about_psmid_title'];
$about_psmid_content = $_POST['about_psmid_content'];
$hidden_auth_user = $_POST['hidden_auth_user'];
$now = (new \DateTime())->format('Y-m-d H:i:s');
$stmt = $db->prepare('INSERT INTO tblcontent (title, content, posted_by, when_inserted, posttype) VALUES (?,?,?,?,?)');
$stmt ->bind_param('sssss', $about_psmid_title, $about_psmid_content, $hidden_auth_user, $now, $about_psmid_page);
$stmt ->execute();
echo json_encode('Successfully Inserted');
}
?>