Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Obviously, without supplying your code and database schema one can not see what your problem may be.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Is there anyone who might be able to help me with this? The book referred me to this forum for possible help on issues that arise.If it's supplying more information, please let me know and I'll do what I can. I can't go any further with the exercises until this is resolved or incorporate into an existing site I'm working on and under a tight schedule at this late stage. In other words, help!
Copy link to clipboard
Copied
near the end of the code is a place to insert data into the database.
// insert the details in the database
$data = array('first_name' => $_POST['first_name'],
'family_name' => $_POST['surname'],
'username' => $_POST['username'],
'password' => sha1($_POST['password']));
Where's the area for email?
Copy link to clipboard
Copied
Man you nailed it. It appears to be a missing script line in the book and accompanying download files, unless I missed something somewhere else in the tutorial. iPHP thank you so much for solving this one. What a relief to be able to move on. Great job! David Powers if you're out there take note, this refers to the associative array under step 2, top of p. 247 of the tutorial using Zend_db to insert user details into the database.
The missing line 5 of the associative array is
'email' => $_POST['email']);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now