Parse error: syntax error, unexpected T_STRING - PLEASE HELP

Hey i am trying to understand what the problem with the following code
I get the following error: Parse error: syntax error, unexpected T_STRING on line 2

[code]<?php parseString($searchterm); if (strlen($searchterm_clean) > 0) { $searchterm = $searchterm_clean;} $keywords = explode(" ", $searchterm); $sql = “SELECT DISTINCT *, date_format(date, ‘%a %c/%e/%Y’) as date_reformated FROM $table_sermons“; if ($_GET[‘q’]) { $sql .=” WHERE”; $i = 1; foreach ($keywords as $keyword) { if (count($keywords) == $i) { // If this is the last keyword $sql .= “(title LIKE ‘%$keyword%’ OR speaker LIKE ‘%$keyword%’ OR series LIKE ‘%$keyword%’ OR scripture LIKE ‘%$keyword%’)”; } else { $sql .= "(title LIKE ‘%$keyword%’ OR speaker LIKE ‘%$keyword%’ OR series LIKE ‘%$keyword%’ OR scripture LIKE ‘%$keyword%’) AND "; } $i++; }} $counttotal_sql = $sql;$counttotal = mysql_query($counttotal_sql) or die(mysql_error()); // select all records$counttotal = mysql_num_rows($counttotal); // count records$total_pages = ceil($counttotal / $max); // dive the total, by the maximum results to show //$counttotal_sql = $sql . " GROUP BY id “; $sql .= " ORDER BY date DESC, tod DESC, sermon_number DESC, id DESC LIMIT $cur, $max”; $query = mysql_query($sql) or die(mysql_error()); // select the results if ($counttotal == 0) { echo "
No sermons found.

“;}else { $begin = $cur + 1;$end = $cur + $max;if ($end > $counttotal) { $end = $counttotal;} echo " rn”;echo " rn";echo " “;echo " “;echo " “;echo " “;echo “”;echo " rn”;echo "
rn”; echo " rn”;echo " Showing “;echo $begin . ‘–’ . $end . ’ of ’ . $counttotal;echo “.rn”;echo " rn”;echo "
rn”;echo " rn";echo " rn"; while($sermon = mysql_fetch_array($query)) { extract($sermon); $number = $number + 1; //result number $remainder = $number % 2; //gives either a 1 or a 0 if ($remainder == ‘1’) { echo " rn"; } else { echo "
rn"; } echo " rn"; echo “$sermon[title]”; echo “<” . “br>rn”; echo “$sermon[speaker]”; if (!empty($sermon[‘series’])) { echo " • $sermon[series]"; } echo “<” . “br>rn”; echo scripture_link($sermon[‘scripture’]); echo " rn"; echo " rn"; echo "$sermon[date_reformated] “; echo strtoupper($sermon[‘tod’]); echo “”; echo “<” . “br>rn”; echo “MP3 (Downloaded $sermon[downloads] “; if ($sermon[‘downloads’] !=1) { $return = ‘times’; } else { $return = ‘time’; } echo “$return) rn”; echo "
rn”;} echo " nn”; if ($total_pages > 1) { echo " nn”; if ($page > 1){ // is the page number more than 1? $prev = ($page - 1); // if so, do the following. take 1 away from the current page number echo “”; echo "« Previous "; // echo a previous page link } for ($i = 1; $i <= $total_pages; $i++) { // for each page number if ($page == $i) { // if this page were about to echo = the current page echo "$i "; // echo the page number bold } else { echo "$i "; // echo a link to the page } } if ($page < $total_pages){ // is there a next page? $next = ($page+ 1); // if so, add 1 to the current echo “Next »”; // echo the next page link }}}?>

[/code]

Hi,
If you are using the code as displayed in the post then most likely your problem is related to having comments and code all in the same line.
// this is a comment if { bla bla …this won’t work
I suggest cleaning up your code having one command per line.
For example:
if ($page == $i)
{
// if this page were about to echo = the current page
echo "$i ";
// echo the page number bold
}
else { echo "$i "; // echo a link to the page
} } if ($page < $total_pages){
// is there a next page?
$next = ($page+ 1);
// if so, add 1 to the current
echo “Next »”; // echo the next page link
}

This will make debugging, reading, and maintaining the code much simpler.

I believe gordonk66 has definitely hit the nail on the head here (certainly to start anyway).

Although you CAN put more than one command per line, separated by a semi-colon ; for readability and debugging it’s not always wise to do so.

You can even run comments IN-LINE using this method, but this is where you really got into trouble.

there are (basically) 2 ways to comment in PHP

Method 1
// comments AFTER a double forward slash will comment anything AFTER that point on a single LINE ONLY.

Method 2
[b]/* comments AFTER a forward slash followed by an asterisk will be commented
and can Span MULTIPLE lines up until you get to the CLOSING
comment mark which is the reverse of the opening. An asterisk followed by a Forward Slash. */

As I took a “Brief” look at your code, I did a “Simple” Substitution (to make it easier to look at) and replaced EVERY semi-colon ; with a semi-colon ; AND a carriage return. Then Immediately noticed things like
//result number $remainder = $number % 2;
and
//gives either a 1 or a 0 if ($remainder == ‘1’) { echo " rn";

So the code will Definitely Fail.

Sponsor our Newsletter | Privacy Policy | Terms of Service