Help me with Parse error: syntax error, unexpected T_STRING...

Discussion in 'PHP' started by IanT, Aug 15, 2010.

  1. #1
    With the following test script I receive and error:



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html
    	xmlns="http://www.w3.org/1999/xhtml"
    	lang="en"
    	xml:lang="en"
    >
    <head><title>Test MySQL</title></head>
    <body>
    <!-- mysql_up.php -->
    <?php
    $host=”localhost”;
    $user=”ma56779_test”;
    $password=”test”;
    mysql_connect($host,$user,$password);
    $sql=”show status”;
    $result = mysql_query($sql);
    if ($result == 0)
    echo “<b>Error “ . mysql_errno() . “: “
    . mysql_error() . “</b>”;
    else
    {
    ?>
    <!-- Table that displays the results -->
    <table border=”1”>
    <tr><td><b>Variable_name</b></td><td><b>Value</b>
    </td></tr>
    <?php
    for ($i = 0; $i < mysql_num_rows($result); $i++) {
    echo “<TR>”;
    $row_array = mysql_fetch_row($result);
    for ($j = 0; $j < mysql_num_fields($result); $j++)
    {
    echo “<TD>” . $row_array[$j] . “</td>”;
    }
    echo “</tr>”;
    }
    ?>
    </table>
    <?php } ?>
    </body></html>
    Code (markup):

    Error:

    
    Parse error: syntax error, unexpected T_STRING in /home/ma56779/public_html/miscstuff/projects/mysql_up.php on line 16
    
    Code (markup):

    how do I fix this?

    Thanks for the help!
     
    IanT, Aug 15, 2010 IP
  2. jpratama

    jpratama Member

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    This kind of error is a very common thing and you have get used to it to be able to debug easily. It means the PHP engine confused with your syntax 'grammar' when it tried to translate your command. It can be missing semi colon, brackets or else. It gave the direction for you already that you must find line 16 to fix the error. I found on around that line, it seemed you missed the SQL command as your query instead you filled it with string "show status".

    mysql_connect($host,$user,$password);
    $sql=”show status”;
    $result = mysql_query($sql);
    PHP:
     
    jpratama, Aug 15, 2010 IP
  3. IanT

    IanT Well-Known Member

    Messages:
    503
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #3
    i fixed it!
     
    IanT, Aug 15, 2010 IP