gpt4 book ai didi

php - 语法错误(语法明显不错)

转载 作者:行者123 更新时间:2023-12-03 08:03:23 24 4
gpt4 key购买 nike

// 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上搜索了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>

最佳答案

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

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

您只是放了转义的正斜杠,转义了引号而不是换行符。发生这种情况时,字符串在技术上不会结束,您会遇到问题。尽管错误在第63行,但是PHP读取了63的意图,而64则是问题所在。出现T_ENCAPSED错误时,如果在该行上没有看到任何内容,请务必检查周围的行。

关于php - 语法错误(语法明显不错),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5085931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com