Hi,
I have been building a registration form and i am near complete! but i am having a probelm with the data adding to the database correctly.
First my code:
$sql ="SELECT (MAX(`user_id`) + 1) FROM bb_users";
$row = mysql_query($sql,$connection) or die(mysql_error());
$user_id = $row;
$username = $_POST['username'];
$email = $_POST['email'];
$new_password = $_POST['new_password'];
$website = $_POST['website'];
$occupation = $_POST['occupation'];
$location = $_POST['location'];
$interests = $_POST['interests'];
$yim = $_POST['yim'];
$msn = $_POST['msn'];
$results = mysql_query("INSERT INTO bb_users (user_id, username, user_password, user_email, user_website, user_occ, user_from, user_interests, user_yim, user_msnm)
VALUES ('$user_id', '".$username."', '".MD5('$new_password')."', '$email', '$website', '$occupation', '$location', '$interests', '$yim', '$msn')", $connection) or die(mysql_error());
$results1 = mysql_query("INSERT INTO bb_groups (group_name, group_description, group_single_user, group_moderator)
VALUES ('', 'Personal User', 1, 0)", $connection) or die(mysql_error());
$sql ="SELECT MAX(group_id) AS gtotal FROM bb_user_group";
$grow = mysql_query($sql,$connection) or die(mysql_error());
$group_id = $grow['gtotal'] + 1;
$results2 = mysql_query("INSERT INTO bb_user_group (user_id, group_id, user_pending)
VALUES ($user_id, $group_id, 0)", $connection) or die(mysql_error());
echo "Congrats, Registration is Complete.<BR><BR>You May Now Login!";
This section here:
$sql ="SELECT (MAX(`user_id`) + 1) FROM bb_users";
$row = mysql_query($sql,$connection) or die(mysql_error());
$user_id = $row;
Its surposed to add up all the rows in the table then add 1 too it, so then this become the user_id. But what i am getting is, you add it once and when you want to add another user, i get duplicate key.
The stranges thing ever tho,
$sql ="SELECT MAX(group_id) AS gtotal FROM bb_user_group";
$grow = mysql_query($sql,$connection) or die(mysql_error());
$group_id = $grow['gtotal'] + 1;
This works fine! but when i try and do the same with the user_id i just get the same error, add 1, next is a duplicate key.
my registion is also for phpbb, my registration should be, you only register on the site, as the user wont have access to it, unless i give them permission, i got that working fine, but i just cant get this thing out of the way.
Another thing, when that 1 user is registered, on the forum whos online, it doesnt update with the newest member, it should do it automatically when the new user registers, yet its not a phpbb problem due to if you register there it works.
Really hope someone can help me finish this.
Thanks
Aaron