Hey guys, any help at all on this would be most appreciated!
I’m having a problem at the moment running a registration form - what I want to do is have a user sign up, so that when they submit their registration form it takes the ID (auto incremented) of the user and forms a directory under members/clubs/$member_id - the code I think is right is below, but any help would be most appreciated!
[php]<?php
//Start session
session_start();
//Include database connection details
require_once('config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect(REMOVED, REMOVED, REMOVED);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(gafferzo_clubdatabase);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$fname = clean($_POST['fname']);
$lname = clean($_POST['lname']);
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$cpassword = clean($_POST['cpassword']);
$clubname = clean($_POST['clubname']);
//Input Validations
if($fname == '') {
$errmsg_arr[] = 'First name missing';
$errflag = true;
}
if($lname == '') {
$errmsg_arr[] = 'Last name missing';
$errflag = true;
}
if($login == '') {
$errmsg_arr[] = 'Login ID missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password missing';
$errflag = true;
}
if($cpassword == '') {
$errmsg_arr[] = 'Confirm password missing';
$errflag = true;
}
if($clubname == '') {
$errmsg_arr[] = 'Club name missing';
$errflag = true;
}
if( strcmp($password, $cpassword) != 0 ) {
$errmsg_arr[] = 'Passwords do not match';
$errflag = true;
}
//If there are input validations, redirect back to the registration form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: register-form.php");
exit();
}
//Create INSERT query
$qry = "INSERT INTO members(firstname, lastname, login, passwd, clubname)
VALUES(’$fname’,’$lname’,’$login’,’".md5($_POST[‘password’])."’,’$clubname’)";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
header("location: register-success.php");
exit();
}else {
die("Query failed");
}
//Fetch club ID
$result = mysql_query("SELECT * FROM clubdatabase");
$row = mysql_fetch_array( $result );
mkdir('/home/gafferzo/www/members/clubs/$row['member_id']', 0777);
?>[/php]
Any help on this at all would be greatly appreciated