...

View Full Version : "syntax error, unexpected $end " Please help :S ???



Loic
01-07-2008, 06:04 AM
Hi all, i am getting this error and i cant work out why... could someone please help????


Parse error: syntax error, unexpected $end in /home/loic/public_html/dev/search.php on line 120



<?php
include ("includes/global.php");

$template = new Template;
$template->load("includes/default.htm");

$connections = mysql_connect($host, $username, $password) or die ( "Unabale to connect to the database" );
mysql_select_db($db_name) or die ( "Unable to select database!" );

$limit = 10;

$var = @$_GET['q'] ;
$trimmed = trim($var);
$trimmed_array = explode(" ",$trimmed);


if ($trimmed == "") {
$resultmsg = "<p>Search Error</p><p>Please enter a search...</p>" ;
}
if (!isset($var)){
$resultmsg = "<p>Search Error</p><p>We don't seem to have a search parameter! </p>" ;
}

foreach ($trimmed_array as $trimm){
$query = "SELECT * FROM items WHERE title LIKE \"&#37;$trimm%\" OR mini_dec LIKE \"%$trimm%\" OR main_dec LIKE \"%$trimm%\" ORDER BY id DESC" ;
$numresults=mysql_query ($query);
$row_num_links_main =mysql_num_rows ($numresults);
if (empty($s)) {
$s=0;
}
$query .= " LIMIT $s,$limit" ;
$numresults = mysql_query ($query) or die ( "Couldn't execute query" );
$row= mysql_fetch_array ($numresults);
do{
$adid_array[] = $row[ 'id' ];
}while( $row= mysql_fetch_array($numresults));
}

if($row_num_links_main == 0 && $row_set_num == 0) {
$resultmsg = "<p>Search results for:" . $trimmed ."</p><p>Sorry, your search returned zero results</p>" ;
}
$tmparr = array_unique($adid_array);
$i=0;
foreach ($tmparr as $v) {
$newarr[$i] = $v;
$i++;
}
$body .= <<<EOD
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="get" action="search.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr><td colspan="3"><strong>Search </strong></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="text" name="q" value="$var" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" value="Search"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<hr />
EOD;
if( isset ($resultmsg)){
$body .= $resultmsg;
$template->replace("title", "Search");
$template->replace("meta", "");
$template->replace("body", $body);
$template->publish();
exit();
}else{
$body .= "Search results for: " . $var;
}
foreach($newarr as $value){
$query_value = "SELECT * FROM items WHERE id = '$value'";
$num_value=mysql_query ($query_value);
$row_linkcat= mysql_fetch_array ($num_value);
$row_num_links= mysql_num_rows ($num_value);

$titlehigh = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'title' ] );
$linkhigh = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'mini_dec' ] );
$linkdesc = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'main_dec' ] );

foreach($trimmed_array as $trimm){
if($trimm != 'b' ){
$titlehigh = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $titlehigh);
$linkhigh = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $linkhigh);
$linkdesc = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $linkdesc);
}
$body .= <<<EOD
<p>$titlehigh; <br>
$linkhigh; <br>
$linkdesc; </p>
EOD;
}
if($row_num_links_main > $limit){
if ($s>=1) {
$prevs=($s-$limit);
$body .= "<div align='left'><a href='$PHP_SELF?s=$prevs&q=$var&catid=$catid'>Previous " .$limit. "</a></div>";
}
$slimit =$s+$limit;
if (!($slimit >= $row_num_links_main) && $row_num_links_main!=1) {
$n=$s+$limit;
$body .= "<div align='right'><a href='$PHP_SELF?s=$n&q=$var&catid=$catid'>Next " .$limit. "</a></div>";
}
}
}
$template->replace("title", "Search");
$template->replace("meta", "");
$template->replace("body", $body);
$template->publish();$end
?>

CFMaBiSmAd
01-07-2008, 07:55 AM
The problem is most likely because the EOD; in the following block of code does not start at column 1 of the line it is in (you can tell that this section of code is the start of the problem because the color highlighting the forum software does, stopped changing at that point.)


$body .= <<<EOD
<p>$titlehigh; <br>
$linkhigh; <br>
$linkdesc; </p>
EOD;

Per the php manual, the heredoc terminator tag must start in column 1 of the line it is in.

Also, the $end; variable you put at the end of the code needs to be removed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum