0

My code is giving an error ( Undefined index: search_string) and I haven't found the solution, how can I sort that out please.

Code below.

   <?php
include('studentheader.php');
include('booksdb.php'); //note we moved this line


if ($_POST) {
$title = $_POST['title'];

$stmt = $DBH->prepare("SELECT * from Books where book_title LIKE '%".$title."%' " );
$stmt->bindParam(1, $title);
$stmt->execute();


include('errordb.php'); 
header("Location:  ");
}
?>
<h2>Search for a book</h2><br></br>   
<form class='form-style' action="searchbook.php" method="post">  
Title: <input type="text" name="title" value="<?php echo $title; ?>" />
<input type="submit" name="submit" value="Search" class='button'/>
</form>
<?php include('studentfooter.php'); ?>
Allen
  • 3
  • 2
  • 1
    You have a field named `title` but you're trying to read `search_string` (?) – FirstOne Nov 27 '17 at 23:40
  • Since your variable is called `title`, I'd say change your code to `$title = $_POST['title'];` – FirstOne Nov 27 '17 at 23:41
  • BTW, this would cause a warning for an undefined variable, since you're not setting `tittle` when the page doesn't receive the POST, but you still try to access it. – FirstOne Nov 27 '17 at 23:42
  • You should try and echo the sql statement – r lo Nov 28 '17 at 00:01
  • Your query's weird. First, you're not really adding a placeholder for title to bind to, second, you'are adding `%...%` twice. – FirstOne Nov 28 '17 at 00:17

0 Answers0