I have a completed selection and then there is a table that I fill out as well, then by clicking on the button the selected result goes to the console, but how to save it to the database? Please help me, I really need your help P.S. Ajax request is not needed
function submit() {
$table.find('tr').each(function(){
var rowValues = {};
$(this).find('td').each(function(i) {
var value = $(this).find("input").val();
rowValues[columnNames[i]] = value;
});
arr.push(rowValues);
});
console.log(arr);
var selector = document.getElementById('category_select');
var id = selector[selector.selectedIndex].id;
console.log(id);
var selector = document.getElementById('patient_select');
var value = selector[selector.selectedIndex].value;
console.log(value); //How i can save result in db ?
$.ajax({
url: 'insert.php',
type: 'POST',
data: {
data: value,
},
dataType: 'json',
beforeSend: function(xhr) {
$('#bt').text('OK');
},
success: function(data) {
$('#bt').text('Send');
alert(data);
}
});
}
my insert.php
<?php
$value = $_POST['value'];
$link = mysqli_connect(
'localhost',
'root',
'',
'answer_result');
if (!$link) {
printf("ERR: %s\n", mysqli_connect_error());
}
mysqli_query($link,"INSERT INTO answer_result_table (`answer_content`, `patient_id`)
VALUES ( '$value', '$value')")
or die(mysqli_error($link));
?>