Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'conditionals'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 3 results

  1. Hello! Please explain to me how gender validations from scripts 2.3 differ from the nested one in script 2.4. I have this in 2.3 (updated with NULL coalescing operator while practicing Pursue section): $gender = $_REQUEST['gender'] ?? NULL; if ($gender == 'M') { $greeting = '<p><strong>Good day, Sir!</strong></p>'; } elseif ($gender == 'F') { $greeting == '<p><strong>Good day, Madam!</strong></p>'; } else { $gender = NULL; echo '<p class="error">Gender must be either "M" or "F"!</p>'; /* You may wonder how this last case may be possible, considering the values are set in the HTML form. If a malicious user creates their own form that gets submitted to your handle_form.php script (which is very easy to do), they could give $_REQUEST[‘gender’] any value they want. */ } and this in 2.4: if (isset($_REQUEST['gender'])) { $gender = $_REQUEST['gender']; if ($gender = 'M') { $greeting = '<p><strong>Good day, Sir!</strong></p>'; } elseif ($gender = 'F') { $greeting = '<p><strong>Good day, Madam!</strong></p>'; } else { $gender = NULL; echo '<p class="error">Gender must be either "M" or "F"!</p>'; /* You may wonder how this last case may be possible, considering the values are set in the HTML form. If a malicious user creates their own form that gets submitted to your handle_form.php script (which is very easy to do), they could give $_REQUEST[‘gender’] any value they want. */ } } else { // $_REQUEST['gender'] is not set. $gender = NULL; echo '<p class="error">You forgot to select your gender!</p>'; } It seems that these scripts do the same job, or I just can't figure out the difference, please help me to understand it. And also I want to if we could use NULL coalescing operator in script 2.4 some way. Thank you!
  2. Placing this in 4th Edition as that's the book I'm working through. I've created a form with three inputs (Agent, Guest, Email) but Agent is not required. I'm trying to display different messages whether Agent is input or not but cannot get that part to work. I know the reset button doesn't work but that's just as the form was copied from an old html page. I'll get into field content validation once I can get past this stage as I have multiple fields to add but need to display different messages on form submission dependent on which fields get completed. <!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html" charset="utf-8"> <title>frm_request_home</title> </head> <body> <?php // Start input validation: // Validate the Agent: if (!empty($_POST['agent'])) { $agent = $_POST['agent']; } else { $agent = NULL; } // Validate the Guest Name: if (!empty($_POST['guest'])) { $guest = $_POST['guest']; } else { $guest = NULL; echo '<p class="error"> You forgot to enter the guest name!</p>'; } // Validate the Email Address: if (!empty($_POST['email'])) { $email = $_POST['email']; } else { $guest = NULL; echo '<p class="error"> You forgot to enter your email address!</p>'; } // Conditional to check for form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // form validation: if (!isset($_POST['agent']) ) { // Print the results if Agent: echo "<p>Thank you <b>$agent</b> for your request for <b>$guest</b>.</p> <p>We will reply to you at <i>$email</i>.</p>\n"; // Print the results if Guest: } elseif (!empty($_POST['guest']) && !empty($_POST['email']) ) { echo "<p>Thank you, <b>$guest</b>, for your request.</p> <p>We will reply to you at <i>$email</i>.</p>\n"; } else { // missing form value. echo '<p class"error"> Please fill out the form again.</p>'; } } // Leave the PHP section and create the HTML form: ?> <table width="98%" border="0" align="center" cellpadding="2" cellspacing="0" class="tblBorder"> <tr> <td align="center" class="txtHeaderRev">Request Form</td> </tr> <tr> <td> <form action="frm_request_home.php" method="post"> <table width="86%" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td align="right" class="txtMain">Agency Name (if applicable):</td> <td><input type="text" name="agent" value="<?php if (isset($_POST['agent'])) echo $_POST['agent']; ?>" style="width:250px;" /></td> </tr> <tr> <td width="46%" align="right" class="txtMain">Guest Name :</td> <td><input type="text" name="guest" value="<?php if (isset($_POST['guest'])) echo $_POST['guest']; ?>" style="width:250px;" /></td> </tr> <tr> <td align="right" class="txtMain">Email Address:</td> <td><input type="text" name="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" style="width:250px;" /></td> </tr> <tr> <td>&nbsp;</td> <td> <input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /> </td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> </form> </td> </tr> </table> </body> </html>
  3. The Switch Conditional exercise on pages 143 - 150 makes us of an undefined variable, var cost; and I'm not sure what role it plays in the code. Do the cost elements in the switch statements load the value into the undefined variable var cost depending upon which condition is met in the document's type value? I can remove these two lines of code, as well as the undefined variable, var cost, and still see the membership form run: var type = document.getElementById('type'); var years = document.getElementById('years'); Why did we create a reference to the document element years when it seems not to be used in the script? Many mysteries have unfolded in this exercise.
×
×
  • Create New...