0

I'm currently trying to build a simple search for a mySQL table using php with PDO, but I don't get any results, so I guess I'm doing something wrong.

Here is what I basically did:

HTML:

<!doctype html>
<html>
<head></head>
<body>
  <form id="search" action="/search.php" method="POST">
    <input type="text" name="searchQ" value="<?php echo $searchQ; ?>">
    <input type="submit" value="Search">
  </form>
</body>
</html>

PHP:

<?php
  $hCon = new PDO("mysql:host=$dbhost_n;dbname=$dbname_n",$dbuser_n,$dbpasswd_n,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
  $searchQ = (isset($_POST['searchQ'])?strtolower(htmlspecialchars($_POST['searchQ'])):"");
  $q = $hCon->prepare("SELECT * FROM :dbTable WHERE LOWER(description) LIKE :searchQ");
  $q->execute(array(':dbTable'=>$dbtable,':searchQ'=>'%'.$searchQ.'%'));

  while($row = $q->fetch(PDO::FETCH_ASSOC)) {
      echo "<p>" . $row['description'] . "</p>";
  }
?>

No matter for what I search, I don't get any results at all. What could be causing this?

cch
  • 3,268
  • 6
  • 31
  • 60
Forivin
  • 13,544
  • 25
  • 91
  • 183

0 Answers0