turtleflame Posted November 6, 2011 Share Posted November 6, 2011 I can't get any of the scripts to work unless I cut and paste them after downloading them. It must be some little thing I'm missing or a typo but I've gone over the scripts over and over comparing what I typed into my code editor to what I cut and pasted and cannot find any discrepencies. This is one example of one that is not working: <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Form Feedback</title> <style type="text/css" title="text/css" media="all"> .error { font-weight: bold; color: #C00; } </style> </head> <body> <?php # Script 2.4 - handle_form2.php #3 // 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 the email: if (!empty($_REQUEST['email'])) { $email = $_REQUEST['email']; } else { $email= NULL; echo '<p class="error">You forgot to enter your email address!</p>'; } // Validate the comments: if (!empty($_REQUEST['comments'])) { $comments= $_REQUEST['comments']; } else { $comments = NULL; echo '<p class="error">You forgot to enter your comments!</p>'; } // Validate the gender: if (isset($_REQUEST['gender'])) { $gender = $_REQUEST['gender]; if ($gender == 'M') { $greeting ='<p><b>Good day, Sir!</b></p>'; } elseif ($gender== 'F') { $greeting = '<p><b>Good day, Madam!</b></p>'; } else { //Unacceptable value. $gender=NULL; echo '<p class="error">Gender should be either "M" or "F"!</p>'; } } else { //$_REQUEST['gender'] is not set. $gender = NULL; echo '<p class="error">You forgot to select your gender!</p>'; } // If everything is OK, print the 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"; echo $greeting; } else { // Missing form value. echo '<p class="error">Please go back and fill out the form again.</p>'; } ?> </body> </html> Am I missing something? Link to comment Share on other sites More sharing options...
turtleflame Posted November 6, 2011 Author Share Posted November 6, 2011 BTW, I changed: <?php # Script 2.4 - handle_form2.php #3 to <?php # Script 2.4 - handle_form.php #3. That didn't work. Link to comment Share on other sites More sharing options...
Jonathon Posted November 6, 2011 Share Posted November 6, 2011 When you say not working, what do you mean? What errors (if any do you get?) One problem is that you haven't matched some quotes up <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Form Feedback</title> <style type="text/css" title="text/css" media="all"> .error { font-weight: bold; color: #C00; } </style> </head> <body> <?php # Script 2.4 - handle_form2.php #3 // 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 the email: if (!empty($_REQUEST['email'])) { $email = $_REQUEST['email']; } else { $email= NULL; echo '<p class="error">You forgot to enter your email address!</p>'; } // Validate the comments: if (!empty($_REQUEST['comments'])) { $comments= $_REQUEST['comments']; } else { $comments = NULL; echo '<p class="error">You forgot to enter your comments!</p>'; } // Validate the gender: if (isset($_REQUEST['gender'])) { $gender = $_REQUEST['gender']; // missing closing ' if ($gender == 'M') { $greeting ='<p><b>Good day, Sir!</b></p>'; } elseif ($gender== 'F') { $greeting = '<p><b>Good day, Madam!</b></p>'; } else { //Unacceptable value. $gender=NULL; echo '<p class="error">Gender should be either "M" or "F"!</p>'; } } else { //$_REQUEST['gender'] is not set. $gender = NULL; echo '<p class="error">You forgot to select your gender!</p>'; } // If everything is OK, print the 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"; echo $greeting; } else { // Missing form value. echo '<p class="error">Please go back and fill out the form again.</p>'; } ?> </body> </html> The code you pasted now validated syntactically in my editor. What editor are you using, a good one should bring these oversights to your attention. Link to comment Share on other sites More sharing options...
turtleflame Posted November 6, 2011 Author Share Posted November 6, 2011 Thanks. I get a white screen. I'm using the code editor on bluehost. Which quotes didn't I match up? Link to comment Share on other sites More sharing options...
Jonathon Posted November 6, 2011 Share Posted November 6, 2011 The ones i noted in the code i posted. What does your source code say then? Do you have display errors off? Link to comment Share on other sites More sharing options...
turtleflame Posted November 6, 2011 Author Share Posted November 6, 2011 I tried turning display errors on in my php.ini file and it didn't work. When I get the white screen and I try to view source code that is blank also. When I cut and pasted your revision of my code above it worked. So maybe it was just the missing quotes. I'm going to try to hand write the code again and see if it works. Link to comment Share on other sites More sharing options...
Jonathon Posted November 6, 2011 Share Posted November 6, 2011 Ask your host to try and alter this for you, it will save you a lot of time in the long run. Or work through the book on a local server. Link to comment Share on other sites More sharing options...
turtleflame Posted November 6, 2011 Author Share Posted November 6, 2011 Okay. Thanks for your help. Link to comment Share on other sites More sharing options...
surow Posted April 24, 2014 Share Posted April 24, 2014 I downloaded phpmysql4_scripts and in folder ch15 I do not find script 15.8 (login.php) There also others that I have not found. Link to comment Share on other sites More sharing options...
HartleySan Posted April 24, 2014 Share Posted April 24, 2014 Hello and welcome to the forums, surow. You sure you got the scripts for the right book and right edition of the book? Link to comment Share on other sites More sharing options...
Larry Posted April 24, 2014 Share Posted April 24, 2014 Sorry for the confusion. It's actually login.html. Link to comment Share on other sites More sharing options...
Recommended Posts