Strange behavior between datatables and php

Strange behavior between datatables and php

desidocdesidoc Posts: 13Questions: 0Answers: 0
edited September 2013 in DataTables 1.9
Hi,

I have this problem: have 2 files ini.php and search.php

the file ini.php contains



function MostrarResultados(){
cate= $("#Combobox1").val();

$.ajax({
type: 'POST',
url: 'search.php',
data:{datos:cate},
success: function(data) {
alert("Data Loaded: " + data); // to see if i get back data form search.php
var oTable = $("#dataTable").dataTable();
oTable.fnClearTable();
oTable.fnDestroy();
$('#dataTable').dataTable( {,
"bServerSide": true,
"sAjaxSource": "../search.php",
"oLanguage": {
"sLengthMenu": "Mostrar _MENU_ Registros por página",
"sZeroRecords": "No se encontró nada",
"sInfo": "Mostrando del _START_ al _END_ de _TOTAL_ Registros",
"sInfoEmpty": "Mostrando del 0 al 0 de 0 Registros",
"sInfoFiltered": "(Filtrado de un total de _MAX_ Registros)"
},
"aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "Todo"]]
});
$("#dataTable_previous").html("Anterior");
$("#dataTable_next").html("Siguiente");
$("#dataTable_filter label").contents().first().remove();
$("#dataTable_filter label input").attr('placeholder', 'Buscar');

}
});
}

On the other hand my search.php contains

<?php
include ('Conex.php');

$datareceived=$_POST['datos'];

$sql = mysqli_query($conex,"SELECT a.description as Description, a.idcategoria as idcategoria FROM categoria a WHERE Active = 'S' AND a.idcategoria = '$datareceived' ");

$aColumns = array( 'Description', 'idcategoria');

$output = array(
"aaData" => array()
);

while ($registro = mysqli_fetch_array($sql))
{
$row = array();
for ( $i=0 ; $i

THE PROBLEM is on the sql sintax and datatables, if i do a.idcategoria = '$datareceived' it doesn't show data on the datatable, although it gives back the data because i can see it in an alert on ini.php.
If i do a.idcategoria = 22 it works perfect, fills the datatable

I compare the output in the two cases with DiffMerge and it's the same in both.

Can anyone please help me, i don´t have any idea of what's happening here and i'm new with this pluging

Thanks

Replies

  • ThalliusThallius Posts: 31Questions: 4Answers: 0
    I could hardly beleive, that both will give you the same output

    a.idcategoria = '$datareceived'

    can not work.

    Did you ever tried

    a.idcategoria = '".$datareceived."'

    Regards

    Claus

    P.S. Use PDO instead of mysql to prevent injections. Also it's much better to debug
  • desidocdesidoc Posts: 13Questions: 0Answers: 0
    Claus thanks for your opinion and advice i'll take notes about PDO.

    I also tried a.idcategoria = '".$datareceived."' it didn't work

    believe me both send me the same output, at first can´t believe but after hours of making test it`s true, sadly for me :(

    Thanks
  • ThalliusThallius Posts: 31Questions: 4Answers: 0
    How do you check the output?
  • desidocdesidoc Posts: 13Questions: 0Answers: 0
    by an alert in the file ini.php and there i can see the structure that search.php send

    i forgot to tell you that also tried with a new variable like $another=22 and it works! but i tried the same with $datareceived and it didn't. I can´t use this variable ¿maybe something in the $_POST?

    I also tried mi query without a.idcategoria = '$datareceived' and works fine
    example:
    $sql = mysqli_query($conex,"SELECT a.description as Description, a.idcategoria as idcategoria FROM categoria a WHERE Active = 'S' ");

    It´s really strange
This discussion has been closed.