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.
<?php
if(isset ($_POST['search']))
{
$valueToSearch=$_POST['valueToSearch'];
//$query="SELECT * FROM `books` WHERE CONCAT (`ISBN`, `Title`, `Author`)LIKE '%".$valueToSearch."%'";
$query="SELECT * FROM books WHERE CONCAT ('ISBN', 'Title', 'Author')LIKE '%".$valueToSearch."%'";
$serach_result=filterTable($query);
}else{
$query="SELECT * FROM books";
$serach_result=filterTable($query);
}
function filterTable($query){
$connect=mysqli_connect ("localhost", "root", "", "bookstore-new");
$filter_result=mysqli_query($connect, $query);
return $filter_result;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Lab 4</title>
<style>
table, tr, th, td
{
border: 1px solid black;
}
</style>
</head>
<body>
<form action="bookstorewebdev.php" method="post">
<input type="text" name="valueToSearch" placeholder="value to search" >
<br><br>
<input type="submit" name="Search" value="Filter" ><br><br>
<table>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Author</th>
</tr>
<?php while ($row=mysqli_fetch_array($serach_result)):?>
<tr>
<td> <?php echo $row['ISBN'];?></td>
<td> <?php echo $row['Title'];?></td>
<td> <?php echo $row['Author'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
</body>
</html>
'ISBN', 'Title', 'Author'columns? Current code is concating that as a string so you are comparingISBNTitleAuthor. This also is open to SQL injections as well.if (!mysqli_query($connect, "YOUR SQL")) { printf("Errormessage: %s\n", mysqli_error($connect)); }