duanouyong4228 2011-02-23 01:02
浏览 83

语法错误(语法明显好)

// 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>
  • 写回答

6条回答 默认 最新

  • dongpuchao1680 2011-02-23 01:04
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程