php - Sql query with punctuation marks -


i have webserver between sql database , android app. on database want put sentence question marks when webserver catches query, echo null. happen when use question marks, dots or commas in phrase. code of webserver is:

<?php $hostname_localhost ="*****"; $database_localhost ="*****"; $username_localhost ="*****"; $password_localhost ="*****"; $localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost) or trigger_error(mysql_error(),e_user_error);  mysql_select_db($database_localhost, $localhost);  $resultado = mysql_query('select pregunta,respuesta,intentos,frase frases'); if (!$resultado) {     die('consulta no vĂ¡lida: ' . mysql_error()); }  while ($fila = mysql_fetch_assoc($resultado)) {     $pregunta = $fila['pregunta'];     $respuesta = $fila['respuesta'];     $intentos = $fila['intentos'];     $frase = $fila['frase'];  }  mysql_close($localhost);  $data = array('pregunta' => $pregunta, 'respuesta' => $respuesta, 'intentos' => $intentos, 'frase' => $frase);  print (json_encode($data));  ?> 

you declaring variables ($pregunta, $respuesta, $intentos, $frase) locally while loop, once while loop completed variables no longer exist.

change:

while ($fila = mysql_fetch_assoc($resultado)) {     $pregunta = $fila['pregunta'];     $respuesta = $fila['respuesta'];     $intentos = $fila['intentos'];     $frase = $fila['frase'];  }  mysql_close($localhost);  $data = array('pregunta' => $pregunta, 'respuesta' => $respuesta, 'intentos' =>     $intentos, 'frase' => $frase);  print (json_encode($data)); 

to:

$data = array();  while ($fila = mysql_fetch_assoc($resultado)) {     $pregunta = $fila['pregunta'];     $respuesta = $fila['respuesta'];     $intentos = $fila['intentos'];     $frase = $fila['frase'];      $data = array('pregunta' => $pregunta, 'respuesta' => $respuesta, 'intentos' =>     $intentos, 'frase' => $frase);  }  mysql_close($localhost);   print (json_encode($data)); 

the data assigned variable outside while loop , retained, allowing output json encoded array.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -