Jump to content


Submitting Regstration Form

  • Please log in to reply
1 reply to this topic

#1 LiLaaron

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 02 May 2006 - 08:18 AM


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:

            $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 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.

#2 .josh

  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 02 May 2006 - 08:40 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users