I have table of data about event management in my website and I want to add search functions to the table based on the "Name" and "Type" of events.
Here is my code by I get errors and also when the user submit the search I need the page to refresh and filter the result in table but this code open a new page with totally clean style-sheet:
I need my page to filter my table based on what user entered in search textbox you can see my table in previous question that I asked please provide easy answers , I'm new to php.
<form action="search.php" id="searchform" method="POST" class="searchbox-container">
<input type="text" id="searchbox" placeholder="Search" name="searchbox" class="searchbox" />
<select name="select" id="select">
<option value="type">Type</option>
<option value="name">Name</option>
</select>
<input type="submit" name="search" class="searchbox-btn" value="Go" />
<?php
if(isset($_POST['searchbox']) && $_POST['searchbox'] !=""){
$search=preg_replace('#[^a-z 0-9?!]#i','',$_POST['searchbox']);
$user="admin";
$pass="neehahs";
$host="localhost";
$db_name="eventregisteration";
$con=mysqli_connect($host, $user, $pass, $db_name);
if(mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if($_POST['select']=="type"){
$sqlcommand="SELECT * FROM eventform WHERE event_type LIKE "%$search%"";
}
elseif($_POST['select']=="name"){
$sqlcommand="SELECT * FROM eventform WHERE event_name LIKE "%$search%""; ===>> this line give Division by zero error
}
$sqldata=mysqli_query($con,$sqlcommand) ==>> this line give mysqli_query(): Empty query error
or die("Error Getting Data");
$count=mysqli_num_rows($sqldata);
if($count>1){
while($row=mysqli_fetch_array($sqldata)){
echo "<table>";
echo "<tr align=center><td>";
echo $row['event_code'];
echo "</td><td>";
echo $row['event_name'];
echo "</td><td>";
echo $row['event_type'];
echo "</td><td>";
echo $row['event_level'];
echo "</td><td>";
echo $row['start_date'];
echo "</td><td>";
echo $row['end_date'];
echo "</td><td>";
echo $row['points'];
echo "</td><td>";
echo $row['pic'];
echo "</td><td>";
echo $row['video'];
echo "</td><td>";
echo $row['description'];
echo "</td></tr>";
}
echo "</table>";
}else{
$search_output="<hr/>0 Results for<strong>$sqldata</strong><hr/>$sqlcommand";
}
}
?>
0 Results for$sqldata
$sqlcommand"; – Shane Nov 22 '13 at 06:33