microlight Posted April 12, 2011 Share Posted April 12, 2011 Hi People. Here is my code from chapter 2 and I get an error I cannot understand, and don't know where I've gone wrong. Please can someone help. Here is the error I get.... Parse error: syntax error, unexpected $end in /Users/dog_snob/Sites/phpmyql3_scripts/ch01/handle_form.php on line 93 From what I understand from the error it is stating that it's reached the end of the file unexpectedly. I've checked each line of code 3 times and can't see the wood for the trees. It is as per the book as far as I can see. <!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>Handle the Form</title> <style type="text/css" title="text/css" media="all"> .error {font-weight: bold; color; #c00 } </style> </head> <body> <?php # ### script 2.4 handle form handle_form.php // Validate the name: if (!empty($_REQUEST['name'])) { $name =$_REQUEST['name']; } else { $name=NULL; echo '<p class="error"> You forgot to enter your name!</p>'; } // validate email if (!empty($_REQUEST['email'])) { $email=$_REQUEST['email']; } else { $email=NULL; echo '<p class="error"> You forgot to enter your email address!</p>'; } // validate comments if (!empty($_REQUEST['comments'])) { $comments=$_REQUEST['comments']; } else { $comments=NULL; echo '<p class="error"> You forgot to enter any comments!</p>'; } // validate gender if (isset($_REQUEST['gender'])); { $gender=$_REQUEST['gender']; if($gender == 'M'){ echo '<p><b>Good Day, Sir!</b></p>'; } elseif ($gender == 'F'){ echo '<p><b>Good Day, Madam!</b></p>'; } else { //$_REQUEST['gender'] is not set $gender = NULL; echo '<p class="error"> You forgot to select your gender!</p>'; } // if everything else is OK then print this message. if ($name && $email && $gender && $comments) { echo "<p> Thank you, <b>$name</b>, for the following comments:</br> <tt>$comments</tt></p> <p>We will reply to you at <i>$email</i>.</p>\n"; } else { // missing form value. echo '<p class="error">Please go back and fill out the form correctly you dickbrain.</p>'; } ?> </body> </html> Link to comment Share on other sites More sharing options...
Jonathon Posted April 12, 2011 Share Posted April 12, 2011 Hi microlight You've missed a brace see my code and I also removed a ';' after an if statement <!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>Handle the Form</title> <style type="text/css" title="text/css" media="all"> .error {font-weight: bold; color; #c00 } </style> </head> <body> <?php # ### script 2.4 handle form handle_form.php // Validate the name: if (!empty($_REQUEST['name'])) { $name =$_REQUEST['name']; } else { $name=NULL; echo '<p class="error"> You forgot to enter your name!</p>'; } // validate email if (!empty($_REQUEST['email'])) { $email=$_REQUEST['email']; } else { $email=NULL; echo '<p class="error"> You forgot to enter your email address!</p>'; } // validate comments if (!empty($_REQUEST['comments'])) { $comments=$_REQUEST['comments']; } else { $comments=NULL; echo '<p class="error"> You forgot to enter any comments!</p>'; } // validate gender if (isset($_REQUEST['gender'])) // removed your ; { $gender=$_REQUEST['gender']; if($gender == 'M'){ echo '<p><b>Good Day, Sir!</b></p>'; } elseif ($gender == 'F'){ echo '<p><b>Good Day, Madam!</b></p>'; } else { //$_REQUEST['gender'] is not set $gender = NULL; echo '<p class="error"> You forgot to select your gender!</p>'; } } // Missing brace // if everything else is OK then print this message. if ($name && $email && $gender && $comments) { echo "<p> Thank you, <b>$name</b>, for the following comments:</br> <tt>$comments</tt></p> <p>We will reply to you at <i>$email</i>.</p>\n"; } else { // missing form value. echo '<p class="error">Please go back and fill out the form correctly you dickbrain.</p>'; } ?> </body> </html> Link to comment Share on other sites More sharing options...
microlight Posted April 12, 2011 Author Share Posted April 12, 2011 Brilliant, thanks, it now works, For the benefit of others following in our footsteps, please could you highlight where the errors were? I would like to see why I am the dickbrain! Regards Microlight. Link to comment Share on other sites More sharing options...
Jonathon Posted April 13, 2011 Share Posted April 13, 2011 For the benefit of others following in our footsteps, please could you highlight where the errors were? I have look carefully at the code, the ; was by the gender validation and the missing brace is highlighted a few lines later 1 Link to comment Share on other sites More sharing options...
Recommended Posts