coyodel Posted October 19, 2010 Share Posted October 19, 2010 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 More sharing options...
kenrbnsn Posted October 19, 2010 Share Posted October 19, 2010 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 More sharing options...
coyodel Posted October 19, 2010 Author Share Posted October 19, 2010 Doh! I knew it was something silly, thanks for the help! Link to comment https://forums.phpfreaks.com/topic/216215-silly-parse-error/#findComment-1123680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.