2

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) : "&nbsp;") . "</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 LIKEoperator, 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

rji rji
  • 697
  • 3
  • 17
  • 37

1 Answers1

2

use

"...WHERE LOWER(NAME) like lower('%".$text."%')...."

Reason:

By default oracle does case Sensitive search . So convert your string to lower and convert db value also to lower and then compare.

Refer here,here

Community
  • 1
  • 1
Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73