General discussion
Keydown function

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%'"smile;

?>
<!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"smile.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'smile; 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>

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 &#039;Type staff id&#039; Thanks Code: &lt;?php include_once &#039;database.php&#039;; if (!empty($kma = $_GET[&#039;kma&#039;])); $result = mysqli_query($conn,&quot;SELECT * FROM staff where sid like &#039;%$kma%&#039;&quot;); ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt; Retrive data&lt;/title&gt; &lt;style type=&quot;text/css&quot;&gt; .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; } &lt;/style&gt; &lt;script type=&quot;text/javascript&quot;&gt; window.onload = function () { document.getElementById(&quot;Text1&quot;).focus(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt; &lt;?php while($row = mysqli_fetch_array($result)) { ?&gt; &lt;table class=&quot;style1&quot; style=&quot;background-image: url(&#039;images/main1.png&#039;); width:900px; height: 543px; margin-left: auto; margin-right: auto;&quot;&gt; &lt;tr&gt; &lt;td class=&quot;style20&quot;&gt; &lt;table class=&quot;style2&quot;&gt; &lt;tr&gt; &lt;td class=&quot;style25&quot;&gt; &lt;/td&gt; &lt;td class=&quot;style26&quot; rowspan=&quot;3&quot;&gt; &lt;table class=&quot;style31&quot;&gt; &lt;tr&gt; &lt;td&gt; &amp;nbsp;&lt;/td&gt; &lt;td&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class=&quot;style32&quot;&gt; &lt;/td&gt; &lt;td class=&quot;style32&quot;&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &amp;nbsp;&lt;/td&gt; &lt;td rowspan=&quot;2&quot;&gt; &lt;img alt=&quot;&quot; src=&quot;images/in.gif&quot; style=&quot;width: 100px; height: 56px; margin-left: 58px; margin-top: 13px&quot; /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &amp;nbsp;&lt;/td&gt; &lt;td&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class=&quot;style27&quot;&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class=&quot;style14&quot;&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class=&quot;style29&quot;&gt; &lt;table class=&quot;style31&quot;&gt; &lt;tr&gt; &lt;td style=&quot;color: #FFFFFF&quot; class=&quot;style35&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style36&quot;&gt; Id&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style37&quot;&gt; :&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot;&gt;&lt;?php echo $row[&quot;sid&quot;]; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style=&quot;color: #FFFFFF&quot; class=&quot;style35&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style36&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style37&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style=&quot;color: #FFFFFF&quot; class=&quot;style35&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style36&quot;&gt; Name&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style37&quot;&gt; :&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot;&gt;&lt;?php echo $row[&quot;name&quot;]; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style=&quot;color: #FFFFFF&quot; class=&quot;style35&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style36&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style37&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style=&quot;color: #FFFFFF&quot; class=&quot;style35&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style36&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style37&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style=&quot;color: #FFFFFF&quot; class=&quot;style35&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style36&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style37&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style=&quot;color: #FFFFFF&quot; class=&quot;style35&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style36&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot; class=&quot;style37&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td style=&quot;color: #FFFFFF; font-size: large;&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;td class=&quot;style30&quot;&gt; &lt;table class=&quot;style12&quot;&gt; &lt;tr&gt; &lt;td class=&quot;style38&quot;&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo &#039;&lt;img src=&quot;data:image/png;base64,&#039;.base64_encode($row[&#039;photo&#039;] ).&#039;&quot; height=&quot;230&quot; width=&quot;188&quot;/&gt;&#039;; ?&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class=&quot;style4&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td class=&quot;style26&quot;&gt; &lt;table class=&quot;style31&quot;&gt; &lt;tr&gt; &lt;td class=&quot;style33&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td class=&quot;style34&quot;&gt;&amp;nbsp; &lt;form action=&quot;test.php&quot; method=&quot;get&quot;&gt; &lt;input type=&quot;text&quot; id=&quot;Text1&quot; name=&quot;kma&quot; style=&quot;width: 100px;&quot; onkeydown=&quot;keydownFunction()&quot;/&gt; &lt;/form&gt; &lt;/td&gt; &lt;td&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class=&quot;style4&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;td class=&quot;style26&quot;&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php } ?&gt; &lt;script&gt; function keydownFunction() { if (event.keyCode == 13 || event.which == 13){ location.reload(); } } &lt;/script&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;
26
0
1
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft