Jump to content
Larry Ullman's Book Forums

turtleflame

Members
  • Posts

    11
  • Joined

  • Last visited

turtleflame's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. <!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>Multidimensional Arrays</title> </head> <body> <p>Some North American States, Provinces, and Territories:</p> <?php # Script 2.7 - multi.php // Create one array: $mexico = array( 'YU' => 'Yucatan', 'BC' => 'Baja California', 'OA' => 'Oaxaca' ); // Create another array: $us = array ( 'MD' => 'Maryland', 'IL' => 'Illinois', 'PA' => 'Pennsylvania', 'IA' => 'Iowa' ); // Create a third array: $canada = array ( 'QC' => 'Quebec', 'AB' => 'Alberta', 'NT' => 'Northwest Territories', 'YT' => 'Yukon', 'PE' => 'Prince Edward Island' ); // Combine the arrays: $n_america = array( 'Mexico' => $mexico, 'United States' => $us, 'Canada' => $canada ); // Loop through the countries: foreach ($n_america as $country => $list) { // Print a heading: echo "<h2>$country</h2><ul>"; // Print each state, province, or territory: foreach ($list as $k => $v) { echo "<li>$k - $v</li>\n"; } // Close the list: echo '</ul>'; } // End of main FOREACH. ?> </body> </html>
  2. I'm getting this error message: "Parse error: syntax error, unexpected '>' in php2.php on line 49" in regards to this line of code: echo "<h2>$country</h2><ul>"; can't figure out what the problem is. Any ideas? Thanks. (I pasted the entire script below.) <!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>Multidimensional Arrays</title> </head> <body> <p>Some North American States, Provinces, and Territories:</p> <?php # Script 2.7 - multi.php // Create one array: $mexico = array( 'YU' => 'Yucatan', 'BC' => 'Baja California', 'OA' => "Oaxaca' ); // Create another array: $us = array ( 'MD' => 'Maryland', 'IL' => 'Illinois', 'PA' => 'Pennsylvania', 'IA' => 'Iowa' ); // Create a third array: $canada = array ( 'QC' => 'Quebec', 'AB' => 'Alberta', 'NT' => 'Northwest Territories', 'YT' => 'Yukon', 'PE' => 'Prince Edward Island' ); // Combine the arrays: $n_america = array( 'Mexico' => $mexico, 'United States' => $us, 'Canada' => $canada ); // Loop through the countries: foreach ($n_america as $country => $list) { // Print a heading: echo "<h2>$country</h2></ul>"; // Print each state, province, or territory: foreach ($list as $k => $v) { echo "<li>$k - $v</li>\n"; // Close the list: echo '</ul>; } // End of main FOREACH ?> </body> </html>
  3. 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.
  4. Thanks. I get a white screen. I'm using the code editor on bluehost. Which quotes didn't I match up?
  5. BTW, I changed: <?php # Script 2.4 - handle_form2.php #3 to <?php # Script 2.4 - handle_form.php #3. That didn't work.
  6. 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?
×
×
  • Create New...