View Full Version : simple registration question

02-05-2008, 02:17 PM
I have just done a registration tutorial but it only has the input fields username, password1,password2 and email.

I want to add firstname, last name and some select menus in the registration, I know it should be easy but can't get it to work. Hoping someone can tell me how to get it working.


if (isset($_POST['submitted'])) {

$errors = array();

require_once ('mysql_connect.php');

if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {

$user = mysql_real_escape_string($_POST['username']);

$query = "SELECT username FROM user_registration WHERE username = '$user'";

$result = @mysql_query($query);

$num = @mysql_num_rows($result);

if ($num> 0) {

$errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';

} else {

$username = mysql_real_escape_string($_POST['username']);


} else {

$errors[] = '<font color="red">Please provide a valid username between 4 and 30 characters.</font>';


if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}', stripslashes(trim($_POST['email'])) )) {

$errors[] = '<font color="red">Please provide a valid email address.</font>';

} else {

$email = mysql_real_escape_string($_POST['email']);


if (!empty($_POST['password1'])) {

if ($_POST['password1'] != $_POST['password2']) {

$errors[] = '<font color="red">The 2 passwords you have entered do not match.</font>';

} else {

$password = $_POST['password1'];


} else {

$errors[] = '<font color="red">Please provide a password.</font>';


if (empty($errors)) {

$a = md5(uniqid(rand(), true));

$query = "INSERT INTO user_registration (username, email, password, active) VALUES ('$username', '$email', SHA('$password'), '$a')";

$result = @mysql_query($query);

if (mysql_affected_rows() == 1) {

02-05-2008, 05:11 PM
hi mate

you have done a tutorial but have not understood the subject

im guessing you have copied the example verbatim

if you come away from a tut with little understanding then that tut has failed. Maybe its a little advanced. you need to understand whats going on

have you tried my vids