Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors',1); // enable php error display for easy trouble shooting
- error_reporting(E_ALL); // set error display to all
- $connect = mysqli_connect("localhost", "root", "", "signup_confirm") or die("Error " . mysqli_error($con));
- if (isset($_POST['search'])) {
- $valueToSearch = mysqli_real_escape($connect, $_POST['valueToSearch']);
- $query = "SELECT * FROM `form` WHERE CONCAT(`student_name`, `city`) LIKE '%".$valueToSearch."%'";
- // don't know what you are trying to search with CONCAT
- // you may try $query = "SELECT * FROM `form` WHERE `student_name` LIKE '%".$valueToSearch."%' OR `city` LIKE '%".$valueToSearch."%'";
- $search_result = filterTable($query);
- } else {
- $query = "SELECT * FROM `form`";
- $search_result = filterTable($query);
- }
- function filterTable($query) {
- global $connect;
- if (!$result = mysqli_query($connect, $query)) {
- return false;
- } else {
- return $result;
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>PHP HTML TABLE DATA SEARCH</title>
- <style>
- table,tr,th,td {
- border: 1px solid black;
- }
- </style>
- </head>
- <body>
- <div align="right">
- <form action="" method="post">
- <input type="text" name="valueToSearch" placeholder="Value To Search" size="40"><br><br>
- <input type="submit" name="search" value="Search Now"><br><br>
- </form>
- </div>
- <table width="1000" border="5" align="center">
- <tr>
- <h1><td colspan="9" align="center" bgcolor="blue"><h1>viewing all the records</h1></td></h1>
- </tr>
- <tr align="center">
- <th>serial no</th>
- <th>Name</th>
- <th>last Name</th>
- <th>father number</th>
- <th>Nic</th>
- <th>mobile number</th>
- <th>Blood group</th>
- <th>gender</th>
- <th>city</th>
- </tr>
- <?php
- if (!$search_result) {
- die('Error :' . mysqli_error($connect));
- } else {
- if (mysqli_num_rows($search_result) == 0) {
- echo '<tr><td colspan="9">no record found</td></tr>';
- } else {
- WHILE ($row = mysqli_fetch_array($search_result)) {
- echo "<tr>";
- echo "<td>{$row['id']}</td>";
- echo "<td>{$row['name']}</td>";
- echo "<td>{$row['last_name']}</td>";
- echo "<td>{$row['f_name']}</td>";
- echo "<td>{$row['nic']}</td>";
- echo "<td>{$row['mobile']}</td>";
- echo "<td>{$row['blood_group']}</td>";
- echo "<td>{$row['gender']}</td>";
- echo "<td>{$row['city']}</td>";
- echo "</tr>";
- }
- }
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement