我的数据库搜索表单有问题。该页面大部分运行良好,但我收到两个错误。
警告:ociexecute() [function.ociexecute]: ORA-00904: *$search_term*: * */search_results.php 第 53 行的无效标识符
警告:ocifetch() [function.ocifetch]:ORA-24374:在第 70 行的 **/search_results.php 中的 fetch 或执行和 fetch 之前定义未完成
我已经评论了相关的行号。如果有人能告诉我为什么会这样,我将不胜感激:)
编辑:忘了提,尽管输入了应该得到结果的搜索词,但表格什么也没显示
编辑 2:当查询更改为 SELECT * FROM Phones 时,它工作正常。它必须与查询有关。
<?php
$search_term = $_POST['search_box'];
/* Set oracle user login and password info */
$dbuser = "**"; /* your login */
$dbpass = "**"; /* your oracle access password */
$db = "**";
$connect = OCILogon($dbuser, $dbpass, $db);
if (!$connect) {
echo "An error occurred connecting to the database";
exit;
}
/* build sql statement using form data */
$query = "SELECT * FROM Phones WHERE Name LIKE ".$search_term;
/* check the sql statement for errors and if errors report them */
$stmt = OCIParse($connect, $query);
echo "SQL: $query<br>";
if(!$stmt) {
echo "An error occurred in parsing the sql string.\n";
exit;
}
OCIExecute($stmt); //line 53
?>
<h1 class="green">PHP and Oracle databases</h1>
<h4>Table: <em>Phones</em></h4>
<div align="center">
<table width="850" border="0" bgcolor="#339933" cellpadding="5" cellspacing="1">
<tr bgcolor="#006633">
<td width="75">ID</td>
<td width="75">Name</td>
<td width="100">Brand</td>
<td width="75">Photo</td>
</tr>
<?php
// Display all the values in the retrieved records, one record per row, in a loop
while(OCIFetch($stmt)) { //line 70
// Start a row for each record
echo("<tr valign=top bgcolor=#ccffcc>");
// Output fields, one per column
// Drainage value in column one
$fg1 = OCIResult($stmt,"ID"); //"ID number";
echo("<td width=75>");
echo ($fg1);
echo("</td>");
// Aspect value in column two
$fg2 = OCIResult($stmt,"NAME");//"Name of product";
echo("<td width=75>");
echo ($fg2);
echo("</td>");
// Temperature value in column three
$fg3 = OCIResult($stmt,"BRAND");//"Brand of product";
echo("<td width=75>");
echo ($fg3);
echo("</td>");
// Height value in column four
$fg4 = OCIResult($stmt,"PHOTO");//"Photo file path";
echo("<td width=75>");
echo ($fg4);
echo("</td>");
// End the row
echo("</tr>");
}
// Close the connection
OCILogOff ($connect);
?>