Jump to content

Archived

This topic is now archived and is closed to further replies.

LiLaaron

Submitting Regstration Form

Recommended Posts

Hi,

I have been building a registion form and i am near complete! but i am having a probelm with the data adding to the database correctly.

First my code:

[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!";

[/code]

This section here:

[code]
$sql ="SELECT (MAX(`user_id`) + 1) FROM bb_users";
            $row = mysql_query($sql,$connection) or die(mysql_error());

            $user_id = $row;
[/code]

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,

[code]
$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;
[/code]

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 registration 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

Share this post


Link to post
Share on other sites
umm.. .why don't you just set the id column as unique key with auto-increment? that way the database automatically makes a new number.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.