我想让这个PHP代码运行,我收到的错误是" PHP Parse错误:语法错误,第54行的/var/www/TestSite1/betting.php意外结束$&# 34;,我多次检查我关闭了所有括号,引号和分号。任何帮助将不胜感激。
<form action="index.php" method="post">
Person: <select name="person">
<option value="Karl">Karl</option>
<option value="Erik">Erik</option>
<option value="Patrick">Patrick</option>
</select>
Money: <input type="text" name="am"><br>
Pass: <input type="text" name="pass"><br>
<input type="submit">
</form>
<?php
$person=$_POST["pass"];
$money=$_POST["am"];
class MyDB extends SQLite3
{
function __construct()
{
$this->open('betting.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully<br>";
}
if ($passwd == '3nt3rpr1s3'){
print "Correct Password<br>";
$sql =<<<EOF
UPDATE people set money = "$money" where person=$pname;
EOF;
} else {
print "\nIncorrect Password!";
}
$ret = $db->exec($sql);
if(!$ret){
echo $db->lastErrorMsg();
} else {
}
$sql =<<<EOF
SELECT * from people;
EOF;
$ret = $db->query($sql);
while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
echo "<br>ID = ". $row['id'] . "\n";
echo "<br>Person = ". $row['person'] . "\n";
echo "<br>Money = ". $row['money'] . "\n";
}
$db->close();
?>
答案 0 :(得分:1)
EOF;
前面都包含空格,heredoc manual
重新格式化:
<form action="index.php" method="post">
Person: <select name="person">
<option value="Karl">Karl</option>
<option value="Erik">Erik</option>
<option value="Patrick">Patrick</option>
</select>
Money: <input type="text" name="am"><br>
Pass: <input type="text" name="pass"><br>
<input type="submit">
</form>
<?php
$person=$_POST["pass"];
$money=$_POST["am"];
class MyDB extends SQLite3
{
function __construct()
{
$this->open('betting.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully<br>";
}
if ($passwd == '3nt3rpr1s3'){
print "Correct Password<br>";
$sql =<<<EOF
UPDATE people set money = "$money" where person=$pname;
EOF;
} else {
print "\nIncorrect Password!";
}
$ret = $db->exec($sql);
if(!$ret){
echo $db->lastErrorMsg();
} else {
}
$sql =<<<EOF
SELECT * from people;
EOF;
$ret = $db->query($sql);
while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
echo "<br>ID = ". $row['id'] . "\n";
echo "<br>Person = ". $row['person'] . "\n";
echo "<br>Money = ". $row['money'] . "\n";
}
$db->close();
?>
答案 1 :(得分:0)
来自heredoc手册页的警告
非常重要的是要注意,带有结束标识符的行必须不包含除分号(;)之外的其他字符。这尤其意味着标识符可能没有缩进,并且在分号之前或之后可能没有任何空格或制表符。认识到结束标识符之前的第一个字符必须是本地操作系统定义的换行符也很重要。这是在UNIX系统上的\ n,包括Mac OS X.结束分隔符后面还必须跟一个换行符。
如果此规则被破坏且结束标识符不是&#34; clean&#34;,则不会将其视为结束标识符,PHP将继续查找。如果在当前文件结束之前未找到正确的结束标识符,则将在最后一行产生解析错误。