I have textbox on page, while press ENTER key it display single record, the problem is when textbox is empty and press ENTER key its display all record from database.
Can some one fix the code when textbox is empty display alert box 'Type staff id'
Thanks
Code:
<?php
include_once 'database.php';
if (!empty($kma = $_GET['kma']));
$result = mysqli_query($conn,"SELECT * FROM staff where sid like '%$kma%'"
;
?>
<!DOCTYPE html>
<html>
<head>
<title> Retrive data</title>
<style type="text/css">
.style1
{
width: 80%;
}
.style2
{
width: 93%;
height: 469px;
margin-top: 0px;
margin-right: 14px;
}
.style4
{
width: 912px;
}
.style12
{
width: 104%;
height: 45px;
margin-top: 0px;
}
.style14
{
width: 912px;
height: 13px;
}
.style20
{
width: 1074px;
}
#page {
margin-left:auto;
margin-right:auto;
width:960px;
}
.style25
{
width: 912px;
height: 87px;
}
.style26
{
width: 210px;
}
.style27
{
width: 912px;
height: 53px;
}
.style29
{
width: 912px;
height: 225px;
}
.style30
{
width: 210px;
height: 225px;
}
.style31
{
width: 100%;
}
.style32
{
height: 23px;
}
.style33
{
width: 63px;
}
.style34
{
width: 105px;
}
#Text1
{
width: 97px;
}
.style35
{
width: 19px;
}
.style36
{
width: 91px;
}
.style37
{
width: 14px;
}
.style38
{
width: 15px;
}
</style>
<script type="text/javascript">
window.onload = function () {
document.getElementById("Text1"
.focus();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<?php
while($row = mysqli_fetch_array($result)) {
?>
<table class="style1"
style="background-image: url('images/main1.png'
; width:900px; height: 543px; margin-left: auto; margin-right: auto;">
<tr>
<td class="style20">
<table class="style2">
<tr>
<td class="style25">
</td>
<td class="style26" rowspan="3">
<table class="style31">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style32">
</td>
<td class="style32">
</td>
</tr>
<tr>
<td>
</td>
<td rowspan="2">
<img alt="" src="images/in.gif"
style="width: 100px; height: 56px; margin-left: 58px; margin-top: 13px" /></td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="style27">
</td>
</tr>
<tr>
<td class="style14">
</td>
</tr>
<tr>
<td class="style29">
<table class="style31">
<tr>
<td style="color: #FFFFFF" class="style35">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style36">
Id</td>
<td style="color: #FFFFFF; font-size: large;" class="style37">
:</td>
<td style="color: #FFFFFF; font-size: large;"><?php echo $row["sid"]; ?></td>
</tr>
<tr>
<td style="color: #FFFFFF" class="style35">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style36">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style37">
</td>
<td style="color: #FFFFFF; font-size: large;">
</td>
</tr>
<tr>
<td style="color: #FFFFFF" class="style35">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style36">
Name</td>
<td style="color: #FFFFFF; font-size: large;" class="style37">
:</td>
<td style="color: #FFFFFF; font-size: large;"><?php echo $row["name"]; ?></td>
</tr>
<tr>
<td style="color: #FFFFFF" class="style35">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style36">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style37">
</td>
<td style="color: #FFFFFF; font-size: large;">
</td>
</tr>
<tr>
<td style="color: #FFFFFF" class="style35">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style36">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style37">
</td>
<td style="color: #FFFFFF; font-size: large;">
</td>
</tr>
<tr>
<td style="color: #FFFFFF" class="style35">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style36">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style37">
</td>
<td style="color: #FFFFFF; font-size: large;">
</td>
</tr>
<tr>
<td style="color: #FFFFFF" class="style35">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style36">
</td>
<td style="color: #FFFFFF; font-size: large;" class="style37">
</td>
<td style="color: #FFFFFF; font-size: large;">
</td>
</tr>
</table>
</td>
<td class="style30">
<table class="style12">
<tr>
<td class="style38">
</td>
<td>
<?php echo '<img src="data:image/png;base64,'.base64_encode($row['photo'] ).'" height="230" width="188"/>'; ?>
</tr>
</table>
</td>
</tr>
<tr>
<td class="style4">
</td>
<td class="style26">
<table class="style31">
<tr>
<td class="style33">
</td>
<td class="style34">
<form action="test.php" method="get">
<input type="text" id="Text1" name="kma" style="width: 100px;" onkeydown="keydownFunction()"/>
</form>
</td>
<td>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="style4">
</td>
<td class="style26">
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
?>
<script>
function keydownFunction() {
if (event.keyCode == 13 || event.which == 13){
location.reload();
}
}
</script>
</form>
</body>
</html>