I am passing JSONObject as input into php script based on that the select query need to execute and fetch the values from database. But the values are not not fetching from database even the values are present in database.
<?php
$username = "xxx";
$password = "xxxx";
$host = "localhost";
$database="xxxxx";
$server = mysql_connect($host, $username, $password);
$connection = mysql_select_db($database, $server);
//$jsonString = file_get_contents('php://input');
$jsonString ='{"ilist":{"ib1":"6","ib2":"5"},"rlist":{},"generelist":{"genere1":"Adventure","genere2":"Animation","genere3":"Comedy","genere4":"Horror","genere5":"Fantasy","genere6":"Mystery"},"yearlist":{}}';
$obj = json_decode($jsonString,true);
$ib=array();
$rn=array();
$genere=array();
$year=array();
foreach ($obj['ilist'] as $key => $value)
{
//echo "<br>------" . $key . " => " . $value;
$ib[$key] = $value;
}
foreach ($obj['rlist'] as $key => $value)
{
//echo "<br>------" . $key . " => " . $value;
$rn[$key] = $value;
}
foreach ($obj['yearlist'] as $key => $value)
{
//echo "<br>------" . $key . " => " . $value;
$year[$key] = $value;
}
$val1=implode(',', $ib);
$val2=implode(',', $rn);
$val4=implode(',', $year);
array_walk($obj['generelist'],function(&$item1, $key){$item1="$item1=1";});
$stringgen = implode(' OR ', $obj['generelist']);
$myquery = "SELECT * FROM Movies WHERE 'it' IN ('$val1') OR `Re` IN ('$val2') OR '". mysql_real_escape_string($stringgen) ."' OR `Year` IN ('$val4')";
$query = mysql_query($myquery);
if ( ! $query ) {
echo mysql_error();
die;
}
for ($x = 0; $x < mysql_num_rows($query); $x++) {
$data[] = mysql_fetch_assoc($query);
}
echo json_encode($data);
mysql_close($server); ?>
But it returns the null value even the values present in the database. Even when i open the php file in the IE from phpmyadmin it throws the null value. what is wrong with the script.