How to post form data to datatables to reload mysql data using php

How to post form data to datatables to reload mysql data using php

mongimongi Posts: 3Questions: 1Answers: 0
edited April 2017 in Free community support

I tried to post form data via jQuery to retrieve data from MySql data but errors occur when I click the button.
I want to use form to send data to datatable request via jQuery to retrieve MySql data on the page(Table). This form sends three data such as programmeID, classID(A/B) and terms (1/2) to filter the student from MySql data. The code below show what I tried so far, please I need help for anyone I appreciate. Thanks

//javascript
$('#myTable').DataTable({
"ajax": {
"url": "datatables/viewData4.php",
"type": "POST",
"data": function(d) {
var frm_data = $('form').serializeArray();
$.each(frm_data, function(key, val) {
d[val.name] = val.value;
});
}
}
});

//viewDat4.php

//my aim is to send data here in order to retrieve data from mysql

if(!empty($_POST)){

$pid = $_POST["progid"];
$classid = $_POST["classid"];
    $terms = $_POST["terms"];

$sql = "SELECT * FROM student WHERE progid = $pid AND class = $classid AND terms = $terms";
$query = $connect->query($sql);

}

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Probably need to provide us a little more information. Is the ajax call being made? Is the server being hit? If it is being hit, what is being passed? If you are only making one call on a button click, you might with to separate out the ajax call from the table.

  • mongimongi Posts: 3Questions: 1Answers: 0

    @bindrid , Please give me any suggestion to solve this problem.

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Again, you need to figure out if the issue is server side or client side. In your ajax call, you can add error: function(err, status) { debugger; console.log(err); },

    if you do not know about the javascript debugger command, be sure to look it up for the type of debugging tool you are using.

  • mongimongi Posts: 3Questions: 1Answers: 0

    I don't know the trick to do that, please I need your help.

This discussion has been closed.