-1

i'm coding a search engine i wrote a form with text input and a button :-

<form class="form-inline my-2 my-lg-0" action="" method="post" name="SearchEngine" enctype="multipart/form-data">
        <div class="form-group">
      <input class="form-control mr-sm-2" name="searchinput" type="search" placeholder="البحث" aria-label="Search">
      </div>
      <div class="form-group">
      <button class="btn btn-outline-Dark my-2 my-sm-0" type="submit" style="direction:RTL;">إبحث</button>
      </div>
    </form>

the back end side [ php code ]

require_once '..\Config.php';

$searchon = $_POST['searchinput'];
$dbCon = "mysql:host=$host;dbname=$db_name";

$PDOCon = new PDO($dbCon, $username, $password);

$stmt = $PDOCon->prepare("SELECT * FROM items WHERE name='$searchon' OR chemicalcom= '$searchon'");
$stmt->execute(); 
$rows = $stmt->fetchall();

echo $rows['name'];

the problem is when is submit a value into the text nothing is echoing

MrObscure
  • 475
  • 3
  • 17

1 Answers1

-1
// to get the EXCEPTIONS
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

try{
  $stmt = $dbh->prepare("SELECT * FROM items WHERE name=:name OR chemicalcom= :chemicalcom");
$stmt->bindParam(':name', $searchon);
$stmt->bindParam(':chemicalcom', $searchon);
$stmt->execute(); 
$rows = $stmt->fetchAll(); // not fetchall && fetchAll you will get an array so you need to loop over it to get the values like

   foreach($rows as $r){
     echo $r['name'];
    }
 } catch (PDOException $ex) {
    echo  $ex->getMessage();
  }
Nadim Al Abdou
  • 768
  • 7
  • 13