Help - Search - Members - Calendar
Full Version: Web search engine
Pixel2Life Forum > Member Tutorials and Requests > Tutorial Requests
lol89
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
Trusttec
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!
lol89
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
CODE
<?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 ?>

<? } ?>

Demonslay
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).

CODE
$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.
lol89
yea man im nobie in this ^^ can u give me some web search script who works 100% ? thx
ISEEDEADPEOPLE
I like the way it is created but need a couple of improvements... biggrin.gif biggrin.gif biggrin.gif
lol89
yet nothing
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.