Jump to content
Larry Ullman's Book Forums

Ed Branson

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by Ed Branson

  1. Sorry, I should have posted the scripts .. they are short as follows: ********************************************************Login.php**************************************************** <?php # login.php - 9.11 // This page both displays and handles the login form. // Need the utilities file: require('includes/utilities.inc.php'); // Create a new form: //set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/local/pear/share/pear/'); set_include_path(get_include_path() . PATH_SEPARATOR .'/home/content/93/11035593/html/PEAR/'); require('HTML/QuickForm2.php'); $form = new HTML_QuickForm2('loginForm'); // Add the email address: $email = $form->addElement('text', 'email'); $email->setLabel('Email Address'); $email->addFilter('trim'); $email->addRule('required', 'Please enter your email address.'); $email->addRule('email', 'Please enter your email address.'); // Add the password field: $password = $form->addElement('password', 'pass'); $password->setLabel('Password'); $password->addFilter('trim'); $password->addRule('required', 'Please enter your password.'); // Add the submit button: $form->addElement('submit', 'submit', array('value'=>'Login')); // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form submission // Validate the form data: if ($form->validate()) { // Check against the database: $q = 'SELECT id, userType, username, email FROM tblUsers WHERE email=:email AND pass=SHA1(:pass)'; $stmt = $pdo->prepare($q); $r = $stmt->execute(array(':email' => $email->getValue(), ':pass' => $password->getValue())); // Try to fetch the results: if ($r) { $stmt->setFetchMode(PDO::FETCH_CLASS, 'User'); $user = $stmt->fetch(); } // Store the user in the session and redirect: if ($user) { // Store in a session: $_SESSION['user'] = $user; // Redirect: header("Location:index.php"); exit; } } // End of form validation IF. } // End of form submission IF. // Show the login page: $pageTitle = 'Login'; include('includes/header.inc.php'); include('views/login.html'); include('includes/footer.inc.php'); ?> ***********************************************************Login.html******************************************* <!-- # login.html - Script 9.12 --> <section class="threeColumns"> <article> <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p> </article> <article class="twoThirds"> <h1>Login</h1> <?php if ($form->isSubmitted() && $form->validate()) { echo '<p class="error">The values submitted do not match those on file!</p>'; }?> <?php echo $form; ?> </article> </section>
  2. The login.php script and add_page.php script, in Chapter 9, both begin by creating a new instance of quickform2 as $form. Then the script tests for "POST" in order to process the $form data ELSE display a blank $form for user input. How does the login.php script run twice without creating an empty $form object each time it runs? In other words, when a $form "submit" occurs; how does the $form object RETURN to the "if($_SERVER['REQUEST_METHOD] == 'POST" section of the login.php script, thereby, bypassing the beginning of the script. The beginning of the script would use the variable $form to create a new instance of quickform2 which would seem to me to over write the form data being submitted? Thank you, I am excited to learn from your books. Sincerely, Ed
×
×
  • Create New...