Strange Syntactical Error

Hi There,
I’m working through an example from Larry Ullman’s PHP Visual Quickstart Guide and am getting a syntax error and I don’t know why. Here’s the problematic code:

if (empty($_POST[‘email’])) {
print ‘

Please enter your email address.

$okay = FALSE;

I’ve typed this directly from the book and it looks fine to me, but I’m still getting a syntax error on the first line. Any ideas? Thanks,

It works fine for me…

Since you sound like you’re just learning PHP, perhaps you didn’t put the php tags around it like this?

if (empty($_POST[‘email’])) {
print ‘

Please enter your email address.

$okay = FALSE;

A good ide will tell you what line your errors are on.

what is the eror message?

Here is the complete code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration Results</title>

<style type="text/css" media="screen">
.error {color: red;}



<h2>Registration Results</h2>

<?php // Script 6.2 - handle_reg.php

/* this script handles 8 values from register.html:
email, password, confirm, month, day, year, color, submit */

// Flag Variable to track success

$okay = TRUE

// Validate the email address

if (empty($_POST['email'])) {
print '<p class="error">Please enter your email address.</p>';
$okay = FALSE;

// Validate the password

if (empty($_POST['password'])) {
print '<p class="error">Please enter your password.</p>';
$okay = FALSE;

// If there are no errors, print a success message

if ($okay) {
print '<p>You have successfully registered.</p>';



The error message is: Parse error: syntax error, unexpected ‘if’ (T_IF) in C:\wamp\www\php\handle_reg.php on line 29

and line 29 is if (empty($_POST[‘email’])) {

Thanks so much for your input on this. I’m trying to truck through this book and this exercise has been quite an obstacle for some reason.

Line 25 is missing the semi colon
[php]$okay = TRUE <—[/php]
should be
[php]$okay = TRUE;[/php]

That is why you get an unexpected if on the next line

Thanks much! Now I’ve learned that the error may not necessarily be on the line the IDE says it is but rather directly before or after it. Cheers!

Sponsor our Newsletter | Privacy Policy | Terms of Service