Jump to content


Photo

Web search engine


  • Please log in to reply
8 replies to this topic

#1 lol89

lol89

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 03 October 2009 - 11:15 AM

Hi how i can make search engine for my page i try with some tutorials from this page but bad luck always some error ? thx in advance

#2 Trusttec

Trusttec

    Young Padawan

  • Members
  • Pip
  • 129 posts
  • Gender:Male
  • Location:Saskatchewan, Canada
  • Interests:Webdesign, Wakeboarding, snowmobling

Posted 03 October 2009 - 05:41 PM

Hello,

Can you provide more specifics? What laungauge is your site coded in? Is your content in a msql database? Be more specific and we will be able to help you!

#3 lol89

lol89

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 04 October 2009 - 10:07 PM

ok here is error:

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\xampp\search\index.php on line 35

here is code what i use
<?php

$var = @$_GET['q']; // get the query for the search engine (if applicable)

$trimmed = trim($var); //trim whitespace from the stored variable

$user = "root"; // AN EDIT IS REQUIRED HERE

$password = "2222";

$host = "localhost";

$dbase = "keywords";

$table = "table";



// Connection to DBase

mysql_connect($host,$user,$pass);

@mysql_select_db($dbase) or die("Unable to select database");

$field_to_search = "field";

$query = "SELECT * FROM $table WHERE $field_to_search LIKE "%$trimmed%" order by id";



$result = mysql_query($query); 

$count =mysql_numrows($result);
?>

<form name="search" method="GET" action="<?=$PHP_SELF?>">

Seach the database for: <input type="text" name="q" />

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

</form>
<?php

if($q == true)

{

exit;

}

elseif($q == false)

{
?>
<form name="search" method="GET" action="<?=$PHP_SELF?>">

Seach all the newsletters for 

<input type="text" name="q" />

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

</form>
<?php
}

if ($trimmed == "")

{

echo "<p>Please enter a search...</p>";

exit;

}



// check for a search parameter

if (!isset($var))

{

echo "<p>We dont seem to have a search parameter!</p>";

exit;

}



$numresults=mysql_query($query);

$numrows=mysql_num_rows($numresults);



if ($numrows == 0)

{

echo "<h4>Results</h4>";

echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";

}



// next determine if s has been passed to script, if not use 0

if (empty($s))

{

$s=0;

}



// get results

$result = mysql_query($query) or die("Couldn't execute query");



if($numrows > 1){ $return = "results";}

else{ $return = "result"; }



// display what the person searched for

echo "<p>Your search for "" . $var . "" returned $numrows $return.</p>";



// begin to show results set

$count = 1 + $s;



while ($r= mysql_fetch_array($result))

{

$id = $r["id"];

$year = $r["year"];

$date = $r["date"];

$title = $r["title"];

$description = $r["description"];



$count++;

?>

<a href="http://www.YOURDOMAIN.com/archive/<? echo $year ?>/<? echo $id ?>.html"><? echo $title ?></a><br /><br />



<? echo $description ?><br />

Result Number: <? echo $count ?>

<? } ?>


#4 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 04 October 2009 - 10:40 PM

Well, what you have is a good ol' parser error. The error gives you the exact information you need to debug your issue. This should be something you can do on your own really. PHP has a great way of handling errors and telling you exactly what went wrong and exactly where.

I see what the problem is immediately. Hopefully you didn't just copy/paste this from the tutorial, because there are several problems with incorrect use of quotes. For example, this line (which is probably what is giving your error later on in the script).

$query = "SELECT * FROM $table WHERE $field_to_search LIKE "%$trimmed%" order by id";

The first set of quotes are double quotes, so anything between double quotes that are not escaped with a backslash is interpreted as a string. So in this case, your string is 'SELECT * FROM $table WHERE $field_to_search LIKE ', which is not the entire string you want. The '%$trimmed%' is not in the string, and really should have given you a parser error there for not having a correct deliminator for a concatenating a string. Replace the double quotes around the $trimmed variable with single quotes.

I also noticed several other problems of the exact same nature. I'll let you hunt them down, as you should be doing if you are just learning PHP.

#5 lol89

lol89

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 05 October 2009 - 06:23 AM

yea man im nobie in this ^^ can u give me some web search script who works 100% ? thx

#6 ISEEDEADPEOPLE

ISEEDEADPEOPLE

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 11 October 2009 - 06:26 AM

I like the way it is created but need a couple of improvements... :) ;) :biggrin:

#7 lol89

lol89

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 12 October 2009 - 11:39 AM

yet nothing

#8 DrewwInc

DrewwInc

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 22 November 2010 - 07:59 AM

<?php
echo 'M2';
?>
<?php
echo 'Me';
?>

#9 kendriya

kendriya

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 08 January 2011 - 04:00 AM

Its simply to say ...........




-----------------------------------------------------------------------------------
lamp training in chennai
plc training in chennai
php course in chennai




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users