the following code is causing me hardship. im trying to get this search going... it counts the rows in the database so there is no problem in connection or selecting the table, but throws an error at the very last line of code the </html> tag. there obviously is a problem in the body of the code but cannot see where. Any suggestions where im going wrong please? :bemused:
<html>
<body>
<?php
$user = "";
$password = "";
$host = "localhost";
$dbase = "BlueprintDB";
$table = "blueprints";
// Connection to DBase
mysql_connect($host,$user,$pass);
mysql_select_db($dbase) or die("Unable to select database");
$var = $_GET['q'] ; // get the query for the search engine (if applicable)
$trimmed = trim($var); //trim whitespace from the stored variable
$field_to_search = "blueprint_id";
$query = "SELECT blueprint_id FROM $table WHERE $field_to_search LIKE \"%$trimmed%\" order by blueprint_id";
$result = mysql_query($query);
if ($count = mysql_num_rows($result)) {
echo $count;
}
else {
print (mysql_error());
}
if ($trimmed == "")
{
echo "Please enter a search";
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"; }
echo "<p>Your search for . $var . returned $numrows $return.</p>";
$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 ?>
<?
if($q == true)
{
exit;
}
elseif($q == false)
{
?>
<form name="Search.php" method="GET" action="<?php echo $PHP_SELF;?>">
Seach Blueprints
<input type="text" name="q" />
<input type="submit" name="search" value="Search" />
</form>
</body>
</html>