java - Syntax Error in PHP API -


i developing android app , need have php api in order app talk sql database.

i having error parsing json on getjarrayfromstring();

i tried log actual error , follows:

03-24 15:41:12.175: e/justdealsutils(480): error parsing json on getjarrayfromstring(); org.json.jsonexception: value database of type java.lang.string cannot converted jsonarray 03-24 15:41:12.175: e/log_tag(480): failed data was: 03-24 15:41:12.175: e/log_tag(480): database query failed have error in sql syntax; check manual corresponds mysql server version right syntax use near 'bcode` '%%' , `btitle` '%%' , `bmodule` '%%'' @ line 1 

now above log clarifies error lies in books.php api follows:

<?php     include("mysqlconnection.php");     header('content-type: application/json');     $from = $_post["from"];     $nr = $_post["nr"];     // variables search     $title = $_post["title"];     $code = $_post["code"];     $price = $_post["price"];     $module = $_post["module"];     $order = $_post["order"];     $by = $_post["by"];       $sql = "set character set utf8";     $db->query($sql);      if(isset($from) && isset($nr)){         // need know how many rows in total query <problem here---> $sql = "select * `books` `bspecialoffer`='false' , `bcode` '%$code%' , `btitle` '%$title%' , `bmodule` '%$module%'";         $query = $db->query($sql);          $rows = array();         $rows[] = array("numrows"=>$db->numrows($query));          // if 2 var set order query after them         if(isset($order) && isset($by)){             $sql .= " order `$order` $by limit $from, $nr";         }else{             $sql .= "limit $from, $nr";         }          $query = $db->query($sql);          if($db->numrows($query)!=0){             while($row = mysql_fetch_assoc($query)) {                 $rows[] =  $row;             }             echo json_encode($rows);         }     }      $db->closeconnection(); ?> 

i confused how statement wrong in php mentioned above in log cat!

is there way of writing following:

$sql = "select * `books` `bspecialoffer`='false' , `bcode` '%$code%' , `btitle` '%$title%' , `bmodule` '%$module%'"; 

your suggestions highly appreciated.

the sql query far correct value you're passing empty.

the value of

    $code = $_post["code"];     $price = $_post["price"];     $module = $_post["module"]; 

are empty. try make sure value setted.

sometime double quote responsable that. try replace them single quote

    $code = $_post['code'];     $price = $_post['price'];     $module = $_post['module']; 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -