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:

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

Please enter your email address.

’;
$okay = FALSE;
}
[/php]

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,
Bill

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?

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

Please enter your email address.

’;
$okay = FALSE;
}
?>[/php]

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration Results</title>

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

</head>


<body>

<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>';
}

?>

</body>
</html>

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.
Bill

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