I am trying to fetch data from oracle database onkeyup function. Here is my HTML code.
<form name="filter_name"action="jqry.php" method="post">
<input class="name" name="name" type="text" id="name">
<input name="submit" type="submit" value="submit" />
</form>
And here is my jquery code:
$(function(){
$("#name").keyup(function() {
var name = $(this).val();
var dataString = 'name='+ name;
if(name!='') {
$.ajax({
type: "POST",
url: "connectdb.php",
data: dataString,
cache: false,
success: function(html) {
alert(html);
}
});
}
return false;
});
});
Initially I have written the query as below in connectdb.php
<?php
$text = $_POST['name'];
// I have given db connections here
$query="SELECT EMP_NAME FROM EMPLOYEES";
$stid = oci_parse($conn, $query);
oci_execute($stid, OCI_DEFAULT);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
oci_free_statement($stid);
oci_close($conn);
?>
For this I am getting the output correctly in the alert as
<table border="1">
<tr>
<td>ABC</td>
</tr>
<tr>
<td>XYZ</td>
</tr>
<tr>
<td>PQR</td>
</tr>
</table>
But when I try to match the name with POST variable i.e, $text
, that I get from onkeyup using LIKE
operator, I am getting empty output though they are name matching the variable. I am not able to understand why the query is failed when I use the below query.
$query = "SELECT EMP_NAME FROM EMPLOYEES WHERE NAME LIKE '%".$text."%'";
example when I type a
in the input box with id="name"
, the output I am getting in alert is as below. That is I am getting zero results.
<table border="1">
</table>
For reference here is my database table structure:
| EMP ID | EMP_NAME |
| 1 | ABC |
| 2 | XYZ |
| 3 | PQR |
Please anyone help me that why I am getting empty results when I use LIKE operator