Question

I have a page that allows users to search for people by their first name. So far I have tried several methods, including oci_bind_by_name but I do not get any results from query. Here is my current code:

if(isset($_GET['FirstName_Search'])){
    $stid_check = oci_parse($conn, 'SELECT ID,UserName,Prefix,FirstName,LastName,Suffix,Title,Phone,Email,Department FROM WCM_People WHERE FirstName LIKE '%$FirstName%' ORDER BY LastName,FirstName');

    // bind values to the parameters in the parsed sql string
    //oci_bind_by_name($stid_check, ":FirstName", $FirstName);
    //oci_bind_by_name($stid_check, ":LastName", $LastName);
    $r = oci_execute($stid_check);
    while ($row = oci_fetch_array($stid_check, OCI_ASSOC+OCI_RETURN_NULLS)) {
    echo "<tr>";
    foreach ($row as $item) {
    echo "<td>" . $item . "</td> \n";
    }
    echo "</tr>";
}

    // free the sql statement when finished
    oci_free_statement($stid_check);
}

And here are the warnings and errors that come with it:

   Warning: Division by zero     
   Warning: oci_fetch_array(): ORA-24338: statement handle not executed

It says the ORA-24338 error is coming from this line:

while ($row = oci_fetch_array($stid_check, OCI_ASSOC+OCI_RETURN_NULLS)) {
Was it helpful?

Solution

As per OP's request to close the question.

Change your query using double quotes:

($conn, "SELECT ID,... LIKE '%$FirstName%' ORDER BY LastName,FirstName")

You are using single quotes for the search query while wrapping your query inside single quotes as well, which will not be rendered correctly and will in turn generate an error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top