0

I have obviously seen other threads related to the matter and couldn't solve my problem. I am not experienced with php. My file structure is like:

 -search/
    -index.jade
    -search.php
    css/
      index.css

My index.jade code:

    html
    head
      script(src='https://code.jquery.com/jquery-3.1.0.min.js')
      link(href="css/index.css", rel="stylesheet", type="text/css")

    body 

      form(id="search", method="POST", action="search.php")
        input(type="text",placeholder="Search for...",name="search_bar")
        input(type="submit",name="submit") 

My search.php code:

<?php

$SQL_HOST = "peanuts";
$SQL_PSWD = "more_peanuts";
$SQL_USER = "peanuts_again";
$SQL_DB = "no_peanuts";

// jk...

try {
$link = new mysqli($SQL_HOST, $SQL_USER, $SQL_PSWD, $SQL_DB);  
} catch (Exception $e) {
echo "PDO connection error: " . $e->getMessage();
exit(1);
}

$search = $_POST['search_bar']."*";

$search_query = $link->prepare("SELECT name FROM products WHERE MATCH(name) AGAINST (? IN BOOLEAN MODE)");
$search_query->bind_param('s', $search);
$search_query->execute();
$search_query->store_result();
$search_rows = $search_query->num_rows;
$search_query->bind_result($product_name);

if($search_rows > 0) {

while($search_query->fetch()) {

echo "Your search returned $search_rows results";
echo "$product_name <br>";

}

} 

else {

    echo "Your search returned no results, sorry :(";

}   

?>

I keep getting: "Cannot POST /search/search.php". Help?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
DigitalEvolution
  • 345
  • 2
  • 5
  • 16

0 Answers0