• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

unexpected T_while [php]

wickedgenius

New Member
When I try to use the following script i get an error:

PHP:
mysql_connect("localhost", "aurillia_wicked", "maisie")or die("cannot connect"); 
mysql_select_db("aurillia_clandb")or die("cannot select DB");

$sql = "select * from news limit 5";
$sql_result = mysql_query($sql) or die(mysql_error());

$display_block = "<table cellpadding=10 border=1>"

while ($row = mysql_fetch_array($sql_result)) {
    $news = $rows["content"];
    $author = $rows["author"];
    $added = $rows["added"];
    $display_block .= "<tr>
                           <td>
                               <div align=left>
                               ". $added ."
                           </td>
                           <td>
                               <div align=right>
                               ". $author ."
                           </td>
                       </tr>
                       <tr>
                           <td rowspan=2>
                           ". $news ."
                           </td>
                       </tr>";
}

And the error says:

Parse error: syntax error, unexpected T_WHILE in /home/aurillia/public_html/login_success.php on line 21

Can anyone help me.
 
This often confuses people, since you concentrate on finding what's wrong with the while.
Change this:
Code:
$display_block = "<table cellpadding=10 border=1>";
 
Thanks!

They should rethink the whole error thing to tell the bit bit of code thats wrong.

I bet loads of people have had this sort of problem.
 
Thanks!

They should rethink the whole error thing to tell the bit bit of code thats wrong.

I bet loads of people have had this sort of problem.

Once you know all about php and how it works, the errors do actually make sense.

In the most basic terms, php expects every statement to end with a semi-colon so an unexpected T_* will mean you forgot to end the statement immediately before it, thus Ze does not expect to encounter it.
 
This is a bit off topic, but why do do while $row, then define everything inside the while with $rows?

People use $row because it's what's written as default in the php manual, and therefore most tutorial sites, so it's how people learn it when they don't have a specific variable name to use. I believe he's using $rows because he's creating rows of a table to display his data in HTML.
 
Back
Top