tags:

views:

108

answers:

2
+2  Q: 

PHP Syntax Error

I get the following error:

Parse error: syntax error, unexpected T_STRING in /home/www
/mariam.awardspace.info/php/pageCen.html on line 87

The code that generates the error:

$rows=mysql_num_rows($result);
print "<table border=1>\n";
print "<tr><th>Avatar</th><th>E-mail</th><th>Comments</th></tr>";
     for($i=0; $i<$rows; $i++) {
      // each call return a new record from the query, it contains both number/value and name/value pairs
        $row = mysql_fetch_array($result);

     // either use numbers 0,1,2 etc.. or the column name from the MySQL table to get the values

     if ($i%2 == 0)
         print "<tr id = 'shade'>
                <td>$row[img]</td><td><a href ='mailto:$row[email]'>$row[email]</a></td>
                <td>$row[comments]</td><td>
                <input type=button value='Disapprove' ></td></tr>";
   }

   print "</table>";

The error is under the if statement: if ($i%2 == 0)

+2  A: 

I think you're either missing the opening { (left curly brace) for the if ($i%2 == 0) statement or you;re missing the closing } for the for loop.

Try changing this:

if ($i%2 == 0)

to read this:

if ($i%2 == 0) {

and make sure you have a closing } for the for loop.

Mark Biek
That would cause the for loop to not have a closing brace ...
X-Istence
You shouldn't need braces if it's a one-liner after the `if` statement
John Rasch
True, but my theory is that he's short a } somewhere :) Putting braces around the if() and double-checking the end of the for() would help narrow it down.
Mark Biek
It's better to include them than not include them.
George Stocker
But this is a style thing that is clearly not an answer to the problem at hand.
aehiilrs
The problem is we don't know if it's an issue. We haven't been given enough information.
George Stocker
I agree with Gortok. Cleaning up the code helps track down the issue while teaching good style habits
Mark Biek
With the line he's saying it is blowing up on where it is and the HTML tags before and after the loop, not to mention the actual error message, it seems quite unlikely. More likely is the single quote thing that has been mentioned.
aehiilrs
-1: @Gortok: A mismatched brace will never cause a unexpected T_STRING error.
Andrew Moore
Even if I agree that you are always better off bracing your if statements
Andrew Moore
still the same error i don't how to fix it
@mama I think you're going to have to post more code.
Mark Biek
+4  A: 

My guess is that you opened a string using a single quote ( ' ) higher up in your code and forgot to close it properly. At line 87, you are using single quotes ( ' ) again, closing that string, and causing an unexpected string error.

Andrew Moore