hi im working on a search program using php. below is my codes. its running but when i just click the search button it still print an output. what i want is if i will click the button search without imputing something on its text it will print the message"$output = 'there was no search result'". how will i do that? thanks in advance...
<input type="text" name="search" placeholder="Search...">
<input type= 'submit' name= 'btnsearch' value= 'search' id= 'btnsearch' onclick= 'this.form.action'/>
<input type = 'submit' name = 'download' value = 'save to excel'/>
<?php
mysql_connect("localhost","root","") or die ("could not connect");
mysql_select_db("copylandia") or die ("could not find db");
$output = '';
if(isset($_POST['btnsearch']))
{
$searchq = $_POST['search'];
/*$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);*/
$query = mysql_query("SELECT * FROM user WHERE initial LIKE '%$searchq%' OR lname LIKE '%$searchq%'") or die ("could not search");
$count = mysql_num_rows($query);
if($count == FALSE)
{
$output = 'There was no search results!';
}
else
{
while($row = mysql_fetch_array($query)){
$id = $row['number'];
$Initials = $row['initial'];
$name = $row['fname'];
$lastname = $row['lname'];
$middle = $row['mname'];
$email = $row['emailadd'];
$uname = $row['username'];
$pass = $row['password'];
$Group = $row['group'];
$Position = $row['position'];
$Level1 = $row['level1'];
$Level2 = $row['level2'];
$Level3 = $row['level3'];
$Level4 = $row['level4'];
$Level5 = $row['level5'];
$Level6 = $row['level6'];
$Level7 = $row['level7'];
$output .= 'Initial : '.$Initials.'<br>
First Name : '.$name.'<br>
Last Name : '.$lastname.' <br>
Middle Name : '.$middle.' <br>
Email Add : '.$email.'<br>
Username : '.$uname.'<br>
Password : '.$pass.'<br>
Group : '.$Group.'<br>
Position : '.$Position.'<br>
Level 1 : '.$Level1.'<br>
Level 2 : '.$Level2.'<br>
Level 3 : '.$Level3.'<br>
Level 4 : '.$Level4.'<br>
Level 5 : '.$Level5.'<br>
Level 6 : '.$Level6.'<br>
Level 7 : '.$Level7.'<br>
-------------------------------------<br>';
}
}
print "$output";
}
?>
<?php