KN1V3S Posted September 12, 2021 Share Posted September 12, 2021 Hello everyone, I have a small problem here. I want to create a basic 'searchengine' for my database. Which means: people give an input X for example and this function searches every entry in the database for that input X and shows it in a table to the user. So far, it's showing me every current entry in the database, which is what I wanted. But the problem is, that whenever I make an input for the search, nothing happens. It's as if the page didn't change at all. I took a look earlier in my variables, but I couldn't find anything. Heres my source code. You can also find it in the attachment. <?php if(ISSET($_POST['search'])){ $valueToSearch = $_POST['suchfilter']; $query = "SELECT * FROM `tabelle` WHERE CONCAT(`firstname`, `lastname`, `gender`, `adress`) LIKE'%".$valueToSearch."%'"; $search_result = filterTable($query); } else { $query = "SELECT * FROM `tabelle`"; $search_result = filterTable($query); } function filterTable($query){ $con = mysqli_connect("localhost","root","","csvtest"); $filt_result = mysqli_query($con, $query); return $filt_result; echo $filterTable; } ?> <!DOCTYPE html> <html> <head> <title>Suchfilter</title> </head> <body> <form> <input type="text" name="suchfilter" placeholder="suchwert"><br><br> <input type="submit" name="search" value="Filter"><br><br> <table> <tr> <th>firstname</th> <th>lastname</th> <th>gender</th> <th>adress</th> </tr> <?php while($row = mysqli_fetch_array($search_result)):?> <tr> <td><?php echo $row['firstname'];?></td> <td><?php echo $row['lastname'];?></td> <td><?php echo $row['gender'];?></td> <td><?php echo $row['adress'];?></td> </tr> <?php endwhile;?> </table> </form> </body> </html> I'd appreciate an answer since this is something really important to me. Best regards Knives source.txt Quote Link to comment https://forums.phpfreaks.com/topic/313730-php-database-searchfunction-doesnt-work-as-intented/ Share on other sites More sharing options...
requinix Posted September 12, 2021 Share Posted September 12, 2021 Compare this if(ISSET($_POST['search'])){ $valueToSearch = $_POST['suchfilter']; with this <form> If you're still unsure, try describing to yourself precisely how a <form> submits its data to the server. Quote Link to comment https://forums.phpfreaks.com/topic/313730-php-database-searchfunction-doesnt-work-as-intented/#findComment-1589869 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.