Some Query Issue


#1

Hello,

This is my query…,

$sschoolnamenew=$_GET['sschoolnamenew'];
$spname=$_GET['spname'];
$sfrom=$_GET['sfrom']; 
$sto=$_GET['sto'];

echo $sql="SELECT * FROM `products`  
                         where (school_id is null or school_id=:sschoolnamenew) AND
                        (pcat_id is null or pcat_id= :spname) ";

  $query = $conn->prepare($sql);

$query->bindParam(':sschoolnamenew', $sschoolnamenew);
$query->bindParam(':spname', $spname);
$query->execute();

But it wont run what i did wrong…?

any suggestion please…


#2

Two thoughts.

  1. does the query run when you run it manually against the database?
  2. When you run it, are you using the same values that are passed in with these variables?
echo "sschoolnamenew: {$sschoolnamenew} spname: {$spname}";