Simple PHP Error

Hi

I’m a total noob. I’m trying to create a search engine that retrieves pages from just my website. I created the MySQL database with the appropriate columns (id, title, description, keywords, url) but there is just one error with my PHP coding that I just can’t figure out.

The error in Dreamweaver is shown on line 49 where the “else” is at the very bottom, followed by the “echo”.

Do you have an idea as to why there is an error?

Thank you!

[php]

Search Engine

Search

' />
<?php $search = $_GET['search']; $terms = explode(" ", $search); $query = "SELECT * FROM search WHERE ";
foreach ($terms as $each){
	$i++;
	if ($i == i)
		$query .= "keywords LIKE '%$each%' ";
	else
		$query .= "OR keywords LIKE '%$each%' ";
}

// connect
mysql_connect("localhost", "bigass55_employ", "kvI)1CM;Sp5]");
mysql_select_db("bigass55_employ");

$query = mysql_query($query);
$numrows = mysql_num_rows($query);

if ($numrows > 0) {
	
	while ($row = mysql_fetch_assoc($query)) {
		$id = $row['id'];
		$title = $row['title'];
		$description = $row['description'];
		$keywords = $row['keywords'];
		$url = $row['url'];
		
		echo "<h2><a href='$url'>$title</a></h2>
		$description<br /><br />";
}
else
	echo "No results found for \"<b>$search</b>\"";
	//disconnect 
	mysql_close();
	}
?>

[/php]

Hi!

You forgot the ‘{’ after the “else” and the ‘}’ before it.
( the ‘}’ that stands just before the “else” closes the “while” ) :slight_smile:
Good luck,

O.

Thank you so much for your help. The error is gone now. :smiley:

if you din’t notice, I just want to add that in the code you written that if ($i == i) . make it if ($i == 1).

I mean put 1 in place of i . Better Luck :slight_smile:

Okay. I seen that. I appreciate the feedback. Thanks. ;D.

Sponsor our Newsletter | Privacy Policy | Terms of Service