Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMurat Hasdemir
Front End Web Development Techdegree Graduate 20,968 PointsPDO with LIKE statement what Im doing wrong?
ok I'm trying to build a search function but it seems I do something wrong it allways return null no matter what I did.
try {
$oyuncuSQL = $db->prepare("SELECT oyuncuKod,resim1 FROM oyuncu where 'cinsiyet' LIKE :cinsiyet AND sac LIKE :sac AND goz LIKE :goz AND ten LIKE :ten AND boy BETWEEN :boyalt AND :boyust AND kilo BETWEEN :kiloalt AND :kiloust AND yas BETWEEN :yasalt AND :yasust ");
$oyuncuSQL->bindValue(':cinsiyet',$cinsiyet);
$oyuncuSQL->bindParam(':sac',$sac);
$oyuncuSQL->bindParam(':goz',$goz);
$oyuncuSQL->bindParam(':ten',$ten);
$oyuncuSQL->bindParam(':boyalt',$boyalt);
$oyuncuSQL->bindParam(':boyust',$boyust);
$oyuncuSQL->bindParam(':kiloalt',$kiloalt);
$oyuncuSQL->bindParam(':kiloust',$kiloust);
$oyuncuSQL->bindParam(':yasalt',$yasalt);
$oyuncuSQL->bindParam(':yasust',$yasust);
$cinsiyet=filter_var($_POST["cinsiyet"],FILTER_SANITIZE_STRING);
$cinsiyet="%".$cinsiyet."%";
$sac=filter_var($_POST["sac"],FILTER_SANITIZE_STRING);
$sac="%".$sac."%";
$goz=filter_var($_POST["goz"],FILTER_SANITIZE_STRING);
$goz="%".$goz."%";
$ten=filter_var($_POST["ten"],FILTER_SANITIZE_STRING);
$ten="%".$ten."%";
$boyalt=filter_var($_POST["boyalt"],FILTER_SANITIZE_STRING);
$boyust=filter_var($_POST["boyust"],FILTER_SANITIZE_STRING);
$kiloalt=filter_var($_POST["kiloalt"],FILTER_SANITIZE_STRING);
$kiloust=filter_var($_POST["kiloust"],FILTER_SANITIZE_STRING);
$yasalt=filter_var($_POST["yasalt"],FILTER_SANITIZE_STRING);
$yasust=filter_var($_POST["yasust"],FILTER_SANITIZE_STRING);
if ($kiloalt =="") {
$kiloalt=0;
}
if ($kiloust=="") {
$kiloust==999;
}
if ($yasalt =="") {
$yasalt=0;
}
if ($yasust=="") {
$yasust==999;
}
if ($boyalt =="") {
$boyalt=0;
}
if ($boyust=="") {
$boyust==999;
}
$oyuncuSQL->execute();
$conn = null;
2 Answers
Matthew Bilz
15,829 PointsYou have a couple of variables defined using double equals signs, try giving those a single equals sign:
($kiloust=999, $yasalt=0, $boyust=999)
if ($kiloust=="") {
$kiloust==999;
}
if ($yasalt =="") {
$yasalt=0;
}
if ($yasust=="") {
$yasust==999;
}
if ($boyalt =="") {
$boyalt=0;
}
if ($boyust=="") {
$boyust==999;
}
Murat Hasdemir
Front End Web Development Techdegree Graduate 20,968 Pointsnope that didn't work either...
I start to wonder if null return about the query type, I'm trying to implant 3 Between in a one query with 4 LIKE can it be a limitation from PDO or SQL?
Murat Hasdemir
Front End Web Development Techdegree Graduate 20,968 PointsMurat Hasdemir
Front End Web Development Techdegree Graduate 20,968 Pointsah thanks for tip. after 20 hours of work those slip from sight...
still getting empty array but atleast see one part of the problem.
Matthew Bilz
15,829 PointsMatthew Bilz
15,829 PointsHmmmm --- maybe remove the single quotes from your query statement in the prepare stage from cinsiyet:
FROM oyuncu where 'cinsiyet' <--- remove those quotes perhaps.