// 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語法錯誤(顯然具有良好的語法)
在我看來好像逗號和結束「;」是在正確的地方。我已經在'Net for T_CONSTANT_ENCAPSED_STRING'搜索過,但在我發現的討論中發現的異常與此不一樣。如果任何人都可以直接告訴我,我將不勝感激。
下面是使用PHP和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>\n";
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>\n";
exit();
}
}
// display results
echo "<p><b>What is your favorite programming language for developing MySQL applications?</b></p>\n";
// 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>\n";
}
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>\n;
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>\n");
}
print("</table></p>\n");
}
?>
</body>
</html>
</body>
</html>
謝謝!全部......你們搖滾。我打算清理其餘的代碼並嘗試一下。 – zen 2011-02-23 01:10:42