Jabir Jabir - 1 year ago 83
MySQL Question

php search is not displaying the database record

I have a database created in phpmyadmin, with few columns and data inserted.Right now i can display the table with record in the browser. But what i want is to display a particular value by filtering from the database.the following is the piece of code i have written. At this moment if I input any value into the search field it doesn't sort out, and do nothing.

if(isset ($_POST['search']))
//$query="SELECT * FROM `books` WHERE CONCAT (`ISBN`, `Title`, `Author`)LIKE '%".$valueToSearch."%'";
$query="SELECT * FROM books WHERE CONCAT ('ISBN', 'Title', 'Author')LIKE '%".$valueToSearch."%'";
$query="SELECT * FROM books";

function filterTable($query){

$connect=mysqli_connect ("localhost", "root", "", "bookstore-new");
$filter_result=mysqli_query($connect, $query);
return $filter_result;
<!DOCTYPE html>


<title>Lab 4</title>

table, tr, th, td
border: 1px solid black;
<form action="bookstorewebdev.php" method="post">

<input type="text" name="valueToSearch" placeholder="value to search" >
<input type="submit" name="Search" value="Filter" ><br><br>
<?php while ($row=mysqli_fetch_array($serach_result)):?>
<td>&nbsp;<?php echo $row['ISBN'];?></td>
<td>&nbsp;<?php echo $row['Title'];?></td>
<td>&nbsp;<?php echo $row['Author'];?></td>
<?php endwhile;?>


Answer Source

1 - In HTML form you have :

<input type="submit" name="Search" value="Filter">

and code in which you are checking variable : search.

Search != search

2 - You not check the variable valueToSearch. It is can be empty. Request will fail.

3 - About concat you said chris85. Why do you need this?