2014-01-26 50 views
-2

这是我用我的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 ?> 

我得到一个错误说:

Parse error: syntax error, unexpected ':' in /home/jharvard/vhosts/localhost/public/week2/register2.php on line 20

我不明白为什么这种形式,如果别的不工作

回答

5

旻宁在这条线闭架

<? if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]): ?>

应该是你缺少一个)

<? if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"])): ?>

通知后最后支架$_POST['dorm']

+3

另外''应''分号 – MackieeE

+1

不是之前的PHP闭标签 –

+0

由于必要的,是错误是在丢失的支架上的,如果线 – Akshay

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; ?> 
+0

感谢此工作 – Akshay

+1

没问题,很乐意帮忙 –

1

if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]): ?>失踪):

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.)"; 
?>