2014-01-26 74 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.)"; 
?>