This is the search engine code that i create, but it was error and didnt come out the result. Cn u help me to check what wrong with my code?
Thanks
<Table cellspacing=1 cellPadding=1 align=center>
<td colspan=4>
<h2 align=center>Bo mba inventory searching system</h2>
<tr>
<td>
<h4 Balai Bomba Inventory Searching System</H4>
<form name="search" method="post" action="<?=$PHP _SELF?>">
Search for:
<br><input type="text" name="search">
<br><Select NAME="field">
<Option VALUE="Operasi" >Operasi</option>
<Option VALUE="Balai">B alai</option>
<Option VALUE="Komunika si">Komunikas i</option>
</select>
<br><input type="submit"na me="Submit"valu e="Submit"/>
</form>
<?
//required file for database connection
require("config .php");
if (isset($_POST['search'])) {
$search = mysql_real_esca pe_string($_POS T["search"]);
$field=mysql_re al_escape_strin g($_POST["field"]);
echo "<h2>Result s</h2><p>";
//If they did not enter a search term we give them an error
if ($search== "") {
echo "<p>You forgot to enter a search term";
}
//Now we search for our search term, in the field the user specified
$data ="SELECT * FROM listofitem ";
if($field=='Ope rasi'){
$data .="AND listofitem.Nama Peralatan LIKE'%search%'" ;}
elseif($field== 'Balai'){
$data .="AND listofitem.Nama Peralatan LIKE '%search%'";}
elseif($field== 'Komunikasi'){
$data .="AND listofitem.Nama Peralatan LIKE'%search%'" ;}
$result=mysql_q uery($data);
//echo "<tr><td bgcolor='#CCCCF F'>ID</th><td bgcolor='#CCCCF F'>NamaPeralata n</th><td bgcolor='#CCCCF F'>Jenama</td> </tr>";
//And we display the results
if($result && (mysql_num_rows ($result))>0){
while($row = mysql_fetch_ass oc( $result )){
echo "<tr><td><a href='Informati onPage.php?id={ $row['ID']}'>{$result['ID']}</a></td>
<td><a href='Informati onPage.php?id={ $row['NamaPeralatan']}'>{$result['NamaPeralatan']} </td>
<td>{$row['Jenama']}</td>
</tr>";
echo" <b>Searched For:</b> " .$search;
}
}
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mys ql_num_rows($re sult);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
}
//And we remind them what they searched for
?>
<a href='AddNew(op erasi).php?id=S earch Again'>AddNew(O perasi)</a>
<a href='AddNew(Ba lai).php?id=Sea rch Again'>AddNew(B alai)</a>
<a href='AddNew(Ko munikasi).php?i d=Search Again'>AddNew(K omunikasi)</a>
Thanks
<Table cellspacing=1 cellPadding=1 align=center>
<td colspan=4>
<h2 align=center>Bo mba inventory searching system</h2>
<tr>
<td>
<h4 Balai Bomba Inventory Searching System</H4>
<form name="search" method="post" action="<?=$PHP _SELF?>">
Search for:
<br><input type="text" name="search">
<br><Select NAME="field">
<Option VALUE="Operasi" >Operasi</option>
<Option VALUE="Balai">B alai</option>
<Option VALUE="Komunika si">Komunikas i</option>
</select>
<br><input type="submit"na me="Submit"valu e="Submit"/>
</form>
<?
//required file for database connection
require("config .php");
if (isset($_POST['search'])) {
$search = mysql_real_esca pe_string($_POS T["search"]);
$field=mysql_re al_escape_strin g($_POST["field"]);
echo "<h2>Result s</h2><p>";
//If they did not enter a search term we give them an error
if ($search== "") {
echo "<p>You forgot to enter a search term";
}
//Now we search for our search term, in the field the user specified
$data ="SELECT * FROM listofitem ";
if($field=='Ope rasi'){
$data .="AND listofitem.Nama Peralatan LIKE'%search%'" ;}
elseif($field== 'Balai'){
$data .="AND listofitem.Nama Peralatan LIKE '%search%'";}
elseif($field== 'Komunikasi'){
$data .="AND listofitem.Nama Peralatan LIKE'%search%'" ;}
$result=mysql_q uery($data);
//echo "<tr><td bgcolor='#CCCCF F'>ID</th><td bgcolor='#CCCCF F'>NamaPeralata n</th><td bgcolor='#CCCCF F'>Jenama</td> </tr>";
//And we display the results
if($result && (mysql_num_rows ($result))>0){
while($row = mysql_fetch_ass oc( $result )){
echo "<tr><td><a href='Informati onPage.php?id={ $row['ID']}'>{$result['ID']}</a></td>
<td><a href='Informati onPage.php?id={ $row['NamaPeralatan']}'>{$result['NamaPeralatan']} </td>
<td>{$row['Jenama']}</td>
</tr>";
echo" <b>Searched For:</b> " .$search;
}
}
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mys ql_num_rows($re sult);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
}
//And we remind them what they searched for
?>
<a href='AddNew(op erasi).php?id=S earch Again'>AddNew(O perasi)</a>
<a href='AddNew(Ba lai).php?id=Sea rch Again'>AddNew(B alai)</a>
<a href='AddNew(Ko munikasi).php?i d=Search Again'>AddNew(K omunikasi)</a>
Comment