By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 2,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

Can help to check and correct my search engine code?

P: 34
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>Bomba 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">Balai</option>
<Option VALUE="Komunikasi">Komunikasi</option>
</select>

<br><input type="submit"name="Submit"value="Submit"/>

</form>

<?
//required file for database connection
require("config.php");
if (isset($_POST['search'])) {
$search = mysql_real_escape_string($_POST["search"]);
$field=mysql_real_escape_string($_POST["field"]);
echo "<h2>Results</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=='Operasi'){
$data .="AND listofitem.NamaPeralatan LIKE'%search%'";}

elseif($field=='Balai'){
$data .="AND listofitem.NamaPeralatan LIKE '%search%'";}

elseif($field=='Komunikasi'){
$data .="AND listofitem.NamaPeralatan LIKE'%search%'";}

$result=mysql_query($data);


//echo "<tr><td bgcolor='#CCCCFF'>ID</th><td bgcolor='#CCCCFF'>NamaPeralatan</th><td bgcolor='#CCCCFF'>Jenama</td> </tr>";
//And we display the results
if($result && (mysql_num_rows($result))>0){
while($row = mysql_fetch_assoc( $result )){
echo "<tr><td><a href='InformationPage.php?id={$row['ID']}'>{$result['ID']}</a></td>
<td><a href='InformationPage.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=mysql_num_rows($result);
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(operasi).php?id=Search Again'>AddNew(Operasi)</a>
<a href='AddNew(Balai).php?id=Search Again'>AddNew(Balai)</a>
<a href='AddNew(Komunikasi).php?id=Search Again'>AddNew(Komunikasi)</a>
Oct 7 '06 #1
Share this Question
Share on Google+
3 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Firstly, it would be nice to your co members to display your approx 70 lines of code within code or php tags.
Secondly
but it was error and didnt come out the result. Cn u help me to check what wrong with my code?
is not really giving any information on:
  • what the error was
  • what you have done to track the error (like echo traces)
  • how far in the code everything is still working as expected
Please provide the members that information.

Ronald :cool:
Oct 7 '06 #2

P: 34
Firstly, it would be nice to your co members to display your approx 70 lines of code within code or php tags.
Secondly
is not really giving any information on:
  • what the error was
  • what you have done to track the error (like echo traces)
  • how far in the code everything is still working as expected
Please provide the members that information.

Ronald :cool:
my error is what ever the keyword i insert into ,it still come out with the same result even i option in field is different . The selection there seen ike did not function alt all. can u check for me?
Oct 9 '06 #3

ronverdonk
Expert 2.5K+
P: 4,258
my error is what ever the keyword i insert into ,it still come out with the same result even i option in field is different . The selection there seen ike did not function alt all. can u check for me?
You have not answered the questions asked, you just keep on saying: "It does not work as expected". The questions were:
- what the error was, you answered that: "It does not work at all"
- what you have done to track the error (like echo traces)
- how far in the code everything is still working as expected

You have to do that before we go on chasing across your code.

Ronald :cool:
Oct 9 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.