语法错误。无法关闭echo语句

时间:2014-01-03 09:11:58

标签: php echo

我的echo语句有问题。最终结果是它在第一个语句之后回显所有内容,包括所有代码。我知道我的问题可能在我的第一个echo语句中。它说是语法错误,但我似乎无法找到问题。所以我希望有人能发现我的问题。 这是我的代码

<!DOCTYPE html>
<html>
<head>
<title>Registration Result</title>
</head>
<body>
<?php
if(!empty($_POST['userid'])){
 $userid=$_POST['userid'];
}
else{
 $userid=null;
 echo'<p><font color="red">Please enter your userid!</font></p>';
}
if (!empty($_POST['sex'])){
$sex=$_POST['sex'];
}
else{
$sex=null;
echo '<p><font color="red">Please choose your gender!</font></p>';
}
if(!empty($_POST['pwd'])){
$pwd=$_POST['pwd'];
}
else{
$pwd=null;
echo'<p><font color="red">Please enter your password!</font></p>';
}
if(!empty($_POST['name'])){
$name=$_POST['name'];
}
else{
$name=null;
echo '<p><font color="red">Please enter you name!</font></p>';
}
if(!isset($_POST['day'])){
$day=$_POST['day'];
}
else{
$day=null;
echo '<p><font color="red">Please enter you day of birth!</font></p>'
}
if(!isset($_POST['month'])){
$month=$_POST['month'];
}
else{
$month=null;
echo '<p><font color="red">Please enter you month of birth!</font></p>'
}
if(!empty($_POST['year'])){
$year=$_POST['year'];
}
else{
$year=null;
echo '<p><font color="red">Please enter your year of birth!</font></p>'
}
?>
</body>
</html>

结果:

Please enter your userid!
'; } if (!empty($_POST['sex'])){ $sex=$_POST['sex']; } else{ $sex=null; echo '
Please choose your gender!

'; } if(!empty($_POST['pwd'])){ $pwd=$_POST['pwd'];} else{ $pwd=null; echo'
Please enter your password!

'; } if(!empty($_POST['name'])){ $name=$_POST['name'];} else{ $name=null; echo '
Please enter you name!

'; } if(!isset($_POST['day'])){ $day=$_POST['day'];} else{ $day=null; echo '
Please enter you day of birth!

'} if(!isset($_POST['month'])){ $month=$_POST['month'];} else{ $month=null; echo '
Please enter you month of birth!

'} if(!empty($_POST['year'])){ $year=$_POST['year'];} else{ $year=null; echo '
Please enter your year of birth!

'} ?>

6 个答案:

答案 0 :(得分:0)

你忘记了一个结束分号。它会像这样工作:

<?php
if (!empty($_POST['userid'])) {
    $userid = $_POST['userid'];
} else {
    $userid = null;
    echo '<p><font color="red">Please enter your userid!</font></p>';
}
if (!empty($_POST['sex'])) {
    $sex = $_POST['sex'];
} else {
    $sex = null;
    echo '<p><font color="red">Please choose your gender!</font></p>';
}
if (!empty($_POST['pwd'])) {
    $pwd = $_POST['pwd'];
} else {
    $pwd = null;
    echo '<p><font color="red">Please enter your password!</font></p>';
}
if (!empty($_POST['name'])) {
    $name = $_POST['name'];
} else {
    $name = null;
    echo '<p><font color="red">Please enter you name!</font></p>';
}
if (!isset($_POST['day'])) {
    $day = $_POST['day'];
} else {
    $day = null;
    echo '<p><font color="red">Please enter you day of birth!</font></p>';
}
if (!isset($_POST['month'])) {
    $month = $_POST['month'];
} else {
    $month = null;
    echo '<p><font color="red">Please enter you month of birth!</font></p>';
}
if (!empty($_POST['year'])) {
    $year = $_POST['year'];
} else {
    $year = null;
    echo '<p><font color="red">Please enter your year of birth!</font></p>';
}

答案 1 :(得分:0)

echo '<p><font color="red">Please enter you day of birth!</font></p>'; //你错过了分号“;”为3回声

答案 2 :(得分:0)

您的最后三个回复语句缺少结束分号;

答案 3 :(得分:0)

你错过了;这些代码行中的半冒号:

else {
            $day = null;
            echo '<p><font color="red">Please enter you day of birth!</font></p>';
        }
        if (!isset($_POST['month'])) {
            $month = $_POST['month'];
        } else {
            $month = null;
            echo '<p><font color="red">Please enter you month of birth!</font></p>';
        }
        if (!empty($_POST['year'])) {
            $year = $_POST['year'];
        } else {
            $year = null;
            echo '<p><font color="red">Please enter your year of birth!</font></p>';
        }

答案 4 :(得分:0)

PHP未被解释 - 您必须在服务器中启用PHP或启用它以进行适当的文件扩展。我希望你使用的是服务器? ;) 此外,其他人已经提到的此代码中存在一些解析错误(但如果关闭错误报告,您应该将其视为解析错误或空白页面。)

答案 5 :(得分:0)

你缺少3个分号。我现在已经修好了。

echo '<p><font color="red">Please enter you day of birth!</font></p>';}
if(!isset($_POST['month'])){
$month=$_POST['month'];}
else{
$month=null;
echo '<p><font color="red">Please enter you month of birth!</font></p>';}
if(!empty($_POST['year'])){
$year=$_POST['year'];}
else{
$year=null;
echo '<p><font color="red">Please enter your year of birth!</font></p>';}