语法错误(语法明显好)

// the following array description (line 64 of the code) is, to my eye, complete and accurate:

      $choicetext = array("", "C/C++", "Java", "Perl", "PHP", "VB/VBA/VBScript", "Andere");

// but it returns this error message:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /Library/WebServer/Documents/results.php on line 64

It looks to me as if the commas and the ending ';' are in the right places. I have searched the 'Net for T_CONSTANT_ENCAPSED_STRING but anomalies addressed in the discussions I found are not the same as this one. If anyone can set me straight I will be grateful.

Here is the entire web page—an exercise in using PHP and MySQL:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"                         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Survey Results</title>
    </head>

    <body>

    <h2>Survey Results</h2>

    <?php

    $mysqlhost="localhost";
    $mysquluser="zen";
    $mysqlpasswd="••••••••••";
    $mysqldname="test_vote";

// create a connection to the database

    $link =
    @mysql_connect($mysqlhost, $mysqluser, $mysqlpasswd);
    if($link==FALSE) {
    echo "<p><b>Unfortunately, a connection to the database cannot be made and the     results cannot be displayed at this time. Please try again later.</b></p>
    </body></html>
";
    exit();
    }
    mysql_select_db($mysqldbname);
// if questionarre data are available;
// evalutate + store
    function array_item($ar, $key) {
    if(array_key_exists($key, $ar)) return($ar[$key]);
    return(''); }

    $submitbutton = array_item($_POST, 'submitbutton');
    $vote - array_item($_POST, 'vote');

    if($submitbutton=="OK") {
    if($vote>=1 && $vote<=6) {
        mysql_query(
                    "INSERT INTO votelanguage (choice) VALUES ($vote)");
    }
    else {
        echo "<p>Not a valid selection. Please vote again. Back to <a     href=\"vote.html\">questionnaire</a>.</p>
        </body></html>
";
        exit();
    }
    }
// display results
    echo "<p><b>What is your favorite programming language for developing MySQL     applications?</b></p>
";

// number of votes cast
    $result =
    mysql_query("SELECT COUNT(choice) FROM votelanguage");
    $choice_count = mysql_results($result, 0, 0);

// percentages for individual voting categories

    if($choice_count == 0) {
    echo "<p>$choice_count No one has voted yet.</p>
";
    }
    else {
    echo "<p>$choice_count individuals have taken part in this survey: </p>n\";
    $choicetext = array("", "C/C++", "Java", "Perl", "PHP", "VB/VBA/VBScript", "Andere");

    print("<p><table>
;
    for($i=1; $i<=6; $i++) {
        $result = mysql_query(
                              "SELECT COUNT(choice) FROM votelanguage".
                              "WHERE choice - $i");
        $choice[$i] = mysql_result($result, 0, 0);
        $percent - round($choice[$i]/$choice_count*10000)/100;
        print("<tr><td>$choicetext[$i]:</td>");
        print("<td>$percent %</td></tr>
");
    }
    print("</table></p>
");
    }
    ?>
    </body>
    </html>


    </body>
    </html>

The echo statement in the line above escapes the closing ". Remove the \", or add a trailing ". Or maybe what you really want is " rather than n\". You are missing some other "'s as well.

This line is fine, the error is on the previous line where you accidentally escaped a quote.

echo "<p>$choice_count individuals have taken part in this survey: </p>n\";

Note the n\ should be .

Your error is on the prior line:

echo "<p>$choice_count individuals have taken part in this survey: </p>n\";

You escaped the final double quote so the string is continuing to the next line.

echo "<p>$choice_count individuals have taken part in this survey: </p>n\";

should be

echo "<p>$choice_count individuals have taken part in this survey: </p>
";

You've just misplaced your escaping forward slash, escaping the quote instead of the newline character. When this happens, the string doesn't technically end, and you run into problems. Although the error is on line 63, PHP reads that 63 is intended and that 64 is the problem. With T_ENCAPSED errors, always check the surrounding lines if you don't see anything on that line.

Looks like you have $mysqldname instead of : $mysqldbname

Missing a B in the name, could lead to wrong associations.?

It could be issue of PHP Editor, make sure to use professional PHP editor for coding.

If you are using General Text Editor for PHP coding, then it can add up hidden lines and unwanted characters, which can cause issue while parsing PHP code.

Thats how you may miss-judge visible Line 64, whereas including hidden lines it may fall on other one.

This is just caution !