Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Json Data not show in table
03/05/2012
21:00
Avatar
destrutorx
New Member
Members
Forum Posts: 1
Member Since:
03/05/2012
sp_UserOfflineSmall Offline

Hello people.

I'm using PHP to load a JSON to JQGRID but the table is coming empty. I have printed the PHP result and I can't find the error.

My data (created via PHP):

{ "page": "", "total": "0", "records": "3", "rows": [{ "id": "1", "cell": ["teste", "teste", "teste", "teste", "teste"] },{ "id": "3", "cell": ["teste", "teste", "teste", "teste", "teste", "teste", "teste", "teste"] },{ "id": "2", "cell": ["teste", "teste", "teste", "teste", "teste", "teste", "teste", "teste"] }]}

My PHP code:

$conexao = new Conexao;

$code  = mysql_escape_string($_GET['code']);

$page  = mysql_escape_string($_GET['page']);

$limit = mysql_escape_string($_GET['rows']);

$sidx  = mysql_escape_string($_GET['sidx']);

$sord  = mysql_escape_string($_GET['sord']);

if( !$sidx ) { $sidx = 1; }

$contador = Reuniao::total_listar($code, true, 'Ativo'); // select data count in mysql table

if( $contador > 0 ) {

$total_pages = ceil($contador/$limit);

} else $total_pages = 0;

if($page > $total_pages) { $page = $total_pages; }

$start = $limit * $page – $limit;

$linha = Reuniao::listar($code, false, NULL, $sidx, $sord, $start, $limit); // select data in mysql table

$saida = '{ "page": "' . $page . '", "total": "' . $total_pages . '", "records": "' . $contador . '", "rows": [';

$count = 1;

foreach ($linha as $l):

if( $count == count($linha) ) {

$saida .= '{ "id": "' . $l['cod_reuniao'] . '", "cell": ["teste", "teste", "teste", "teste", "teste", "teste", "teste", "teste"] }';

} else {

$saida .= '{ "id": "' . $l['cod_reuniao'] . '", "cell": ["teste", "teste", "teste", "teste", "teste", "teste", "teste", "teste"] },';

}

$count++;

endforeach;

$saida .= ']}';

echo $saida;

Can anyone help me to see what is wrong here?

11/05/2012
21:30
Avatar
brandonkirsch
Ohio
Member
Members
Forum Posts: 9
Member Since:
27/04/2012
sp_UserOfflineSmall Offline

I can't see the definition of Reuniao::listar, but there is a very high chance that your code contains SQL injection vulnerabilities, especially around the page, limit and sord parameters.  You cannot simply mysql_escape some of these parameters and remain protected.

Second, you are building the JSON object by hand, and improperly escaping data (quotes within your values) that would lead to invalid JSON syntax.  Instead of:

foreach ($linha as $l):

if( $count == count($linha) ) {

$saida .= '{ "id": "' . $l['cod_reuniao'] . '", "cell": ["teste", "teste", "teste", "teste", "teste", "teste", "teste", "teste"] }';

} else {

$saida .= '{ "id": "' . $l['cod_reuniao'] . '", "cell": ["teste", "teste", "teste", "teste", "teste", "teste", "teste", "teste"] },';

}

You should try using json_encode to do all of the PHP array to JSON object conversion:

$saida = array();

foreach ($linha as $l):

if( $count == count($linha) ) {

$saida[] = array('id' => $l['code_reuniao'], 'cell' => array('teste', 'teste', 'teste, 'teste', etc....));

} else { 

$saida[] = array('id' => $l['cod_reunaio'], 'cell' => array('teste', 'teste', 'testes', etc...));

}

endforeach;

echo json_encode($saida);

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
26 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information