I want to use this $_POST value in my msql query to get my desired output in table , please help

I want to use this $_POST value in my msql query to get my desired output in table , please help

romnickhusanaromnickhusana Posts: 1Questions: 1Answers: 0
edited March 2021 in Free community support
/////////////////////////////////////////////////////////////////// collectors.php form
<form id="51cformdata"> 

<div id="collectorstablediv" style="padding: 5%;">
<h5>List of Collectors</h5>
<i style="font-size: 12px;"><b>Note:</b> Click the name to select the collector.</i>

<table class="display" id="collectorstable" style="font-family: arial; font-size: 12px;">  
<thead>
<th >#</th>
<th >Collector</th>
<th >Designation</th>  
<th >Account #</th>
<th >Description</th>
</thead>
</table>
</div>
<br>
</form>

**/////////////////////////////////////////////////////////////////// 51C-Collectors-fetch.php **

<?php
session_start();
include('db.php');
include('function.php');


$query = '';

$output = array();
$searchaccount = $_POST["searchaccount"];



$query.= " SELECT * FROM `tbl_collectors` where `description` ='".$searchaccount."'";


$statement = $connection->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$filtered_rows = $statement->rowCount();

foreach($result as $row)
{


$sub_array = array();                       

$sub_array[] = $row["id"];  
$sub_array[] = $row["collector"];
$sub_array[] = $row["designation"];
$sub_array[] = $row["accountnumber"];
$sub_array[] = $row["description"];


$data[] = $sub_array;

} 

$output = array(

    "draw"              =>  intval($_POST["draw"]),
    "recordsTotal"      =>  $filtered_rows,
     "data"             =>  $data,
     "searchaccount"   => $searchaccount,

);
echo json_encode($output);

<?php
>
?>



/////////////////////////////////////////////////////////////////////////  collector.js file

var dayendtable = $('#collectorstable').DataTable({

"processing":true,
"serverSide":true,
"order":[],
"pageLength": 1000,
"bFilter": false,
"paging": false,
"bInfo" : false, 

"ajax":{
    url: "includes/FORM51C/51C-Collectors-fetch.php",
    type:"POST",
 
}

,"initComplete":function( settings, data){

console.log(data);
},   

} ); 

Error messages shown:

the table that displaying is empty

Description of problem:

THANK YOU! =)

Answers

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Can you show me the JSON that is being returned by the server please? Even better would be a link to your page.

    Allan

This discussion has been closed.