Jump to content

silly parse error...


coyodel

Recommended Posts

Howdy all,

 

I finally came correct and started working on more web programming including taking a class locally but I've run into a silly problem with a snippet of code from my textbook.  Can you guys tell me why the "else {" line is generating a parse error?  It feels like the first day of kindergarten again...

 

if (empty($_POST['first_name']) || empty($_POST['last_name']));

echo "<p>You must enter your first and last name.

        Click your browser's Back button to return to the Guest Book.</p>\n";

 

else {        /* <<<error here */

    $FirstName = addslashes($_POST['first_name']);

$LastName = addslashes($_POST['last_name']);

$GuestBook = fopen("guestbook.txt", "ab");

if (is_writeable("guestbook.txt")) {

if (fwrite($GuestBook, $LastName . ", " . $FirstName . "\n"))

echo "<p>Thank you for signing our guest book!</p>\n";

else

echo "<p>Cannot add your name to the guest book.</p>\n";

    }

    else

        echo "<p>Cannot write to the file.</p>\n";

fclose($GuestBook);

}

 

Thanks and I'm sure I'll be back.

Link to comment
https://forums.phpfreaks.com/topic/216215-silly-parse-error/
Share on other sites

You have a semi-colon at the end of the "if" statement, which shouldn't be there. It ends the if statement so the parser doesn't expect to see an "else".

 

This:

<?php
if (empty($_POST['first_name']) || empty($_POST['last_name']));
   echo "<p>You must enter your first and last name.
         Click your browser's Back button to return to the Guest Book.</p>\n";
?>

should be written as

<?php
if (empty($_POST['first_name']) || empty($_POST['last_name'])) {
   echo "<p>You must enter your first and last name.
         Click your browser's Back button to return to the Guest Book.</p>\n";
}
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/216215-silly-parse-error/#findComment-1123679
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.