这是我在html文件中使用的代码
<? if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]): ?>
You must provide your name, gender, and dorm! Go <a href="froshims2.php">back</a>.
<? else: ?>
You are registered! (Well, not really.)
<? endif ?>
我收到错误说:
解析错误:语法错误,意外':'in 第20行/home/jharvard/vhosts/localhost/public/week2/register2.php
我不明白为什么这种形式的if else不起作用
答案 0 :(得分:5)
在此行上缩小结束括号
<? if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]): ?>
应该是
<? if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"])): ?>
注意$_POST['dorm']
答案 1 :(得分:1)
你在if语句的末尾遗漏了一个)
,在endif
之后遗漏了一个分号:
<? if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"])): ?>
You must provide your name, gender, and dorm! Go <a href="froshims2.php">back</a>.
<? else: ?>
You are registered! (Well, not really.)
<? endif; ?>
答案 2 :(得分:1)
if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]): ?>
失踪)在结束之前:
答案 3 :(得分:0)
<?php
if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]))
echo 'You must provide your name, gender, and dorm! Go <a href="froshims2.php">back</a>.';
else
echo "You are registered! (Well, not really.)";
?>