Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    57
    Thanks
    4
    Thanked 0 Times in 0 Posts

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

    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 Code:
    <?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 \"%$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" );
        
    $rowmysql_fetch_array ($numresults);
        do{
            
    $adid_array[] = $row'id' ];
         }while( 
    $rowmysql_fetch_array($numresults));
    }

    if(
    $row_num_links_main == && $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_linkcatmysql_fetch_array ($num_value);
         
    $row_num_linksmysql_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
    ?>
    Last edited by Loic; 01-07-2008 at 05:13 AM.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    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.)

    PHP Code:
        $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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •