I am trying to search my landing page record with search filter (In Procedural method rather than PDO or OPP). Its working fine but I am facing one issue that when I open filter page, no record is displaying until I apply search. Where as I want when ever I open search page, all record should be display here even before applying search filter. and when I apply search, then it should filter record. Here is my code :
<form method="post" action="search1.php?go" id="searchform">
<input type="text" name="name"> <br>
<input type="text" name="address">
<input type="submit" name="submit" value="Search">
</form>
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
$name = $_POST['name'];
$address = $_POST['address'];
require_once "config.php";
$sql="SELECT id, name, address, marks FROM student_record Where name = '$name' && address = '$address'";
//-run the query against the mysql query function
$result = mysqli_query($conn, $sql);
//-create while loop and loop through result set
if(mysqli_num_rows($result) > 0){
while($row=mysqli_fetch_array($result)){
$Id =$row['id'];
$Name =$row['name'];
$Address=$row['address'];
$Marks=$row['marks'];
//-display the result of the array
echo "<table class='table table-bordered table-striped table-hover '>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>Name</th>";
echo "<th>Address</th>";
echo "<th>Marks</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['marks'] . "</td>";
echo "</tr>";
echo "</tbody>";
echo "</table>";
}
} else {
echo "<p>No matches found</p>";
}