Parse error: syntax error (PHP)

port5900

New Member
Messages
150
Reaction score
0
Points
0
<?php

mysql_connect("localhost","root","root");
mysql_select_db("cdcol");

$result = mysql_query("SELECT * FROM cds")

while ($row = mysql_fetch_assoc($result))
{
echo $row["titel"];
}

?>

Can some one tell me why am I getting this error?
"Parse error: syntax error, unexpected T_WHILE in C:\xampp\htdocs\phpconnect.php on line 8"

line 8 being
"while ($row = mysql_fetch_assoc($result))"

Thanks
 

blobtech

New Member
Prime Account
Messages
17
Reaction score
0
Points
1
Parse errors do not have to be specifically on the line it says.
The problem here is that you forgot the semi-colon behind line #6:
PHP:
$result = mysql_query("SELECT * FROM cds")

'Unexpected XX' errors are mostly triggered due to a forgotten semi-colon, bracket or comma.
Just backtrack from the line it said (or word, here T_WHILE) and you'll find it most of the time.

So the code will become:

PHP:
<?php

    mysql_connect("localhost","root","root");
    mysql_select_db("cdcol");

    $result = mysql_query("SELECT * FROM cds");

    while ($row = mysql_fetch_assoc($result))
    {
        echo $row["titel"];
    }

?>
 
Top