Undefined index order, start and length

Undefined index order, start and length

kendeshakendesha Posts: 1Questions: 1Answers: 0

I am trying to create a data table using server-side processing but It seems the post request sent through AJAX has some undefined variables. I am very new to Jquery data tables so any suggestions would be greatly appreciated. I have attached the codes below as well as the errors.

HTML FILE


<html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>Central American Management</title> </head> <body> <div> <input type="hidden" id="UserId" name="UserId" data-id="<?php echo($_SESSION['UserId'])?>"></input> <div class="container-fluid"> <div class="container"> <div class="btnAdd" style="margin: 0px 0px 10px 0px"> <button class="btn btn-primary btn-md" id="add-document"><span>Add Document</span></button> </div> <table id="document_table" class="table table-striped table-bordered"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Country</th> <th>Shared</th> <th>Uploaded BY</th> <th>Uploaded Date</th> <th>Options</th> </tr> </thead> <tbody> </tbody> </table> </div> </div> </div> </div> <div class="modal-container" id="modal-container"></div> <script src="../javascriptfiles/Documents.js"></script> </body> </html>

JS FILE

$(document).ready(function(){
     getDocuments();
       $('#modal-container').on('hidden.bs.modal', function() {
        getDocuments();
    });
});
function getDocuments() {
    $('#document_table').dataTable({
        'processing':true,
       'serverSide':true,
        'ajax': {
        'url': "//centralamericanmanagement.000webhostapp.com/phpfiles/getDocuments.php",
        'type': "POST"
        }
    }); 
  
}

PHP FILE

```
<?php
require_once '../DBConnection/dbConfig.php';

$params = $columns = $totalRecords = $data = array();

$params = $_REQUEST;

$columns = array(
0 => 'documentId',
1 => 'document_name',
2 => 'country_name',
3 => 'shared',
4 => 'user',
5 => 'uploadDate',
6 => 'actions'
);

$where_condition = $sqlTot = $sqlRec = "";

if( !empty($params['search']['value']) ) {
$where_condition .= " WHERE ";
$where_condition .= " ( post_title LIKE '%".$params['search']['value']."%' ";
$where_condition .= " OR post_desc LIKE '%".$params['search']['value']."%' )";
}

$sql_query = " SELECT * FROM getDocuments ";
$sqlTot .= $sql_query;
$sqlRec .= $sql_query;

if(isset($where_condition) && $where_condition != '') {

$sqlTot .= $where_condition;
$sqlRec .= $where_condition;
}
$sqlRec .= " ORDER BY ". $columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." ,".$params['length']." ";
try {
$queryTot = $dbh->query($sqlTot);
$totalRecords = $queryTot->fetchColumn();
$queryRecords = $dbh->query($sqlRec);

while( $row = $queryRecords->fetch()) { 
    $sub_array = array();
    $sub_array[] = $row["documentId"];
    $sub_array[] = $row["document_name"];
    $sub_array[] = $row["country_name"];
    $sub_array[] = $row["shared"];
    $sub_array[] = $row["user"];
    $sub_array[] = $row["uploadDate"];
    $sub_array[] = '<a data-id="'.$row['documentId'].'"  class="btn btn-info btn-sm editbtn" >Edit</a>  <a " data-id="'.$row['documentId'].'"  class="btn btn-danger btn-sm deleteBtn" >Delete</a>';
    $data[] = $sub_array;
}   

$json_data = array(
    "draw"            => intval( $params['draw'] ),   
    "recordsTotal"    => intval( $totalRecords ),  
    "recordsFiltered" => intval($totalRecords),
    "data"            => $data
);

echo json_encode($json_data);

}
catch (PDOException $e){
echo json_encode("Error!: " . $e->getMessage() . "<br/>");
}

<?php > ``` ?>

ERRORS: (Thrown from DB and PHP)

<br />
<b>Notice</b>: Undefined index: order in <b>/storage/ssd4/085/17686085/public_html/phpfiles/getDocuments.php</b> on line <b>36</b><br />
<br />
<b>Notice</b>: Undefined index: in <b>/storage/ssd4/085/17686085/public_html/phpfiles/getDocuments.php</b> on line <b>36</b><br />
<br />
<b>Notice</b>: Undefined index: order in <b>/storage/ssd4/085/17686085/public_html/phpfiles/getDocuments.php</b> on line <b>36</b><br />
<br />
<b>Notice</b>: Undefined index: start in <b>/storage/ssd4/085/17686085/public_html/phpfiles/getDocuments.php</b> on line <b>36</b><br />
<br />
<b>Notice</b>: Undefined index: length in <b>/storage/ssd4/085/17686085/public_html/phpfiles/getDocuments.php</b> on line <b>36</b><br />
"Error!: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LIMIT ,' at line 1<br\/>"

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    There is nothing immediately obvious there I'm afraid.

    Can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Allan

Sign In or Register to comment.