Skip to main content
Known Participant
September 25, 2010
Question

User registration problem - Powers tutorial

I'm working through David Powers latest book, Lesson 7, building a registration system. Everything works except the email column in the users database table never populates when the registration form is submitted. All other fields do just fine except that one. I have compared my working files with the completed tutorial files and the code appears to be the same. I was wondering if anyone might know in general why a registration form might not completely fill all of the columns in the database table? It sounds like a code issue, but again even when I use the completed files from the downloads for the book it is the same result. Any thoughts are greatly appreciated as I'm stumped and don't know how else to get help with this particular dilemma.

This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

September 25, 2010

Obviously, without supplying your code and database schema one can not see what your problem may be.

Translate
bmmotionAuthor
Known Participant
September 25, 2010

Right, there's no question I'm trying to take the path of least resistance here. It's essentially David's code from that chapter of his book. So I'm in a catch-22 and reluctant to post his code without at least his blessing. I was hoping he or someone might recognize a common issue from my paltry explanation and say, "Well it's most likely this or that and here are couple things to look for." May be wishful thinking.

Translate
bmmotionAuthor
Known Participant
September 26, 2010

This is the script for the user registration. Is there anything here that looks suspicious and may be blocking the email information submitted by the form to be populated in the database table? My experience with PHP is limited an not sure if this is helpful to resolving my issue. Please let me know what else would be helpful if there isn't anything obvious here.

<?php
$errors = array();
if ($_POST) {
  // run the validation script
  require_once('library.php');
  try {
     // main script goes here
     $val = new Zend_Validate_Regex('/^[a-z]+[-\'a-z ]+$/i');
     if (!$val->isValid($_POST['first_name'])) {
       $errors['first_name'] = 'Required field, no numbers';
     }
     if (!$val->isValid($_POST['surname'])) {
       $errors['surname'] = 'Required field, no numbers';
     }
     $val = new Zend_Validate();
     $length = new Zend_Validate_StringLength(6,15);
     $val->addValidator($length);
     $val->addValidator(new Zend_Validate_Alnum());
     if (!$val->isValid($_POST['username'])) {
       $errors['username'] = 'Use 6-15 letters or numbers only';
     } else {
       $sql = $dbRead->quoteInto('SELECT user_id FROM users WHERE username = ?', $_POST['username']);
      $result = $dbRead->fetchAll($sql);
       if ($result) {
          $errors['username'] = $_POST['username'] . ' is already in use';
       }
     }
     $length->setMin(8);
     $val = new Zend_Validate();
     $val->addValidator($length);
     $val->addValidator(new Zend_Validate_Alnum());
     if (!$val->isValid($_POST['password'])) {
       $errors['password'] = 'Use 8-15 letters or numbers only';
     }
     $val = new Zend_Validate_Identical($_POST['password']);
     if (!$val->isValid($_POST['conf_password'])) {
       $errors['conf_password'] = "Passwords don't match";
     }
     $val = new Zend_Validate_EmailAddress();
     if (!$val->isValid($_POST['email'])) {
       $errors['email'] = 'Use a valid email address';
     }
     if (!$errors) {
       // insert the details in the database
       $data = array('first_name'  => $_POST['first_name'],
                     'family_name' => $_POST['surname'],
                         'username'    => $_POST['username'],
                         'password'    => sha1($_POST['password']));
       $dbWrite->insert('users', $data);
        header('Location: login.php');
     }
  } catch (Exception $e) {
     echo $e->getMessage();
  }
}

Thanks for any help.

Translate