Steven C Steven C - 2 months ago 16
HTML Question

Warning: ocifetch() [function.ocifetch]: ORA-24374: define not done before fetch or execute and fetch

Here is my simple search bar for a uni assignment:

<form name="search" method="post" action="phone_search.php">
<font size="5">Best Secondhand Mobile Phones Geelong</font> - Search the site:

<input type="text" name="term" />
<input type="submit" name="search" value="Search" />
</form>


Here is my php code which accesses an oracle server:

echo "<h2>Results</h2>";

//Null string entered
if ($term == "")
{
echo "You didn't enter anything!\n";
exit;
}

//Connect to database
$dbuser = "xxxx";
$dbpass = "xxxx";
$db = "SSID";
$connect = OCILogon($dbuser, $dbpass, $db);

//Database connection error
if (!$connect)
{
echo "An error occurred connecting to the database.\n";
exit;
}

//Make all lowercase
$term = strtolower($term);

$query = "'SELECT * FROM Phones WHERE lower($Name) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($OS) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($Chipset) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($CPU) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($GPU) LIKE $term'";

//Perform search
$stmt = OCIParse($connect, $query);

//And display the results
$counter = 0;
while(OCIFetch($stmt))
{
$counter++;
echo OCIResult($stmt, "Name");
echo "<br>";
echo OCIResult($stmt, "OS");
echo "<br>";
echo OCIResult($stmt, "Chipset");
echo "<br>";
echo OCIResult($stmt, "CPU");
echo "<br>";
echo OCIResult($stmt, "GPU");
echo "<br>";
echo "<br>";
}


I get the correct error for a null string, and no null error when something is entered.
However, I think that there is a problem with this line:

$query = "'SELECT * FROM Phones WHERE lower($Name) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($OS) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($Chipset) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($CPU) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($GPU) LIKE $term'";


I keep getting this error:

Warning: ocifetch() [function.ocifetch]: ORA-24374: define not done before fetch or execute and fetch in /home/cstev/public_html/Assignment_2/phone_search.php on line 41


Line 41 is:

while(OCIFetch($stmt))


I have intentionally replaced the login details with 'xxxx' before posting.

When I search for this error, I get: Error in PHP search function
It seems as though someone else had this problem 2 years ago for the same assignment.
The answer that he received was that his search term may have been empty.
I can tell that this is not the same problem that I'm having as per the null string error message working correctly if the search term entered is blank.

If anyone could point me in the right direction, I would be most appreciative!!

For reference, this is my database:

DROP TABLE Phones;

CREATE TABLE Phones
( Name VARCHAR2(50),
OS VARCHAR2(50),
Chipset VARCHAR(50),
CPU VARCHAR(50),
GPU VARCHAR2(50),
Image VARCHAR2(50)
);

INSERT INTO Phones VALUES ('HTC Butterfly S', 'Android OS, v4.2.2 (Jelly Bean)', 'Qualcomm APQ8064T Snapdragon 600', 'Quad-core 1.9 GHz Krait 300', 'Adreno 320', 'images/htc-butterfly-s (1).jpg');

INSERT INTO Phones VALUES ('Huawei Ascend P6', 'Android OS, v4.2.2 (Jelly Bean)', 'Huawei K3V2', 'Quad-core 1.5 GHz', 'N/A', 'images/huawei-ascend-p6-ofic.jpg');

INSERT INTO Phones VALUES ('Oppo R819', 'Android OS, v4.2.1 (Jelly Bean)', 'MediaTek MT6589', 'Quad-core 1.2 GHz', 'PowerVR SGX544', 'images/oppo-r819.jpg');

INSERT INTO Phones VALUES ('Sony Xperia M', 'Android OS, v4.1 (Jelly Bean)', 'Qualcomm Qualcomm Snapdragon S4 Plus MSM8227', 'Dual-core 1 GHz Krait', 'Adreno 305', 'images/sony-xperia-m (1).jpg');

INSERT INTO Phones VALUES ('Samsung Galaxy Core', 'Android OS, v4.1.2 (Jelly Bean)', 'Snapdragon MSM8225 S4 Play', 'Dual-core 1.2 GHz Cortex-A5', 'Adreno 203', 'images/samsung-galaxy-core-gt-i8260 (1).jpg');

INSERT INTO Phones VALUES ('Motorola Moto X', 'Android OS, v4.2.2 (Jelly Bean)', 'Qualcomm MSM8960Pro Snapdragon', 'Dual-core 1.7 GHz Krait', 'Adreno 320', 'images/moto-x.jpg');

commit;

Answer

I guess you forgot the

ociexecute($stmt, OCI_DEFAULT);

After the

$stmt = OCIParse($connect, $query);

And before the:

while(OCIFetch($stmt))

So it would look like this:

//Perform search
$stmt = OCIParse($connect, $query);

// Execute statement
ociexecute($stmt, OCI_DEFAULT);

//And display the results
$counter = 0;
while(OCIFetch($stmt))
{
    $counter++;
...

More here