-2

This is the code I am using within my html file

<? 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 ?>

I get a error saying:

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

I don't understand why this form of if else is not working

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
Akshay
  • 783
  • 6
  • 20

4 Answers4

5

Missing closing bracket on this line

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

Should be

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

note the last bracket after $_POST['dorm']

Cjmarkham
  • 9,484
  • 5
  • 48
  • 81
1

you are missing one ) at the end of your if statement and a semicolon after 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; ?>
Gert B.
  • 2,282
  • 18
  • 21
1

if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]): ?> missing ) at end before :

ggdx
  • 3,024
  • 4
  • 32
  • 48
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.)";
?>
csharp newbie
  • 647
  • 1
  • 12
  • 31