UserId in multiple databases

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

UserId in multiple databases

Post by 4Boredom »

Userid is the prim.ary key for users so that autoincrements... how can I edit the basic info part so that userid inserts with it even tho userid isnt actually being inputted by user in the form?

Code: Select all

$sql = mysql_query("INSERT INTO `users` 
                (`first_name`, `last_name`, `email_address`, `username`, `password`, `signup_date`) VALUES 
                ('" . $first_name . "', '" . $last_name . "','" . $email_address . "', '" . $username . "', '" . $password . "', '" . time() . "')"); 

                $sql = mysql_query("INSERT INTO `basic` 
                (`gender`, `month`, `day`, `year`) VALUES 
                ('" . $gender . "', '" . $month . "','" . $day . "', '" . $year . "')");
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Re: UserId in multiple databases

Post by GeXus »

4Boredom wrote:Userid is the prim.ary key for users so that autoincrements... how can I edit the basic info part so that userid inserts with it even tho userid isnt actually being inputted by user in the form?

Code: Select all

$sql = mysql_query("INSERT INTO `users` 
                (`first_name`, `last_name`, `email_address`, `username`, `password`, `signup_date`) VALUES 
                ('" . $first_name . "', '" . $last_name . "','" . $email_address . "', '" . $username . "', '" . $password . "', '" . time() . "')"); 

                $sql = mysql_query("INSERT INTO `basic` 
                (`gender`, `month`, `day`, `year`) VALUES 
                ('" . $gender . "', '" . $month . "','" . $day . "', '" . $year . "')");


You have to insert it in there... get the userid that it is associated with and...

Code: Select all

$sql = mysql_query("INSERT INTO `basic` 
                (`userid`,`gender`, `month`, `day`, `year`) VALUES 
                ('" . $userid. "," . $gender . "', '" . $month . "','" . $day . "', '" . $year . "')");
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

that makes this error

There has been an error creating your account. Please contact the webmaster.Column count doesn't match value count at row 1
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Did you remember to add the "userid" column to the field list?
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

its in the field list in both databases... however its not in any php... It just creates itself in users and i need it to be recognized in basic

could I do a line in between to bring it up from users so basic can recognize it?
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Are you selecting the userid first, then inserting it? If not, you are probably just inserting '' for userid.

Make sure $userid has a value.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

what do you mean by selecting it first
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

up ^^^
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Re: UserId in multiple databases

Post by blackbeard »

4Boredom wrote:Userid is the prim.ary key for users so that autoincrements... how can I edit the basic info part so that userid inserts with it even tho userid isnt actually being inputted by user in the form?

Code: Select all

$sql = mysql_query("INSERT INTO `users` 
                (`first_name`, `last_name`, `email_address`, `username`, `password`, `signup_date`) VALUES 
                ('" . $first_name . "', '" . $last_name . "','" . $email_address . "', '" . $username . "', '" . $password . "', '" . time() . "')"); 

                $sql = mysql_query("INSERT INTO `basic` 
                (`gender`, `month`, `day`, `year`) VALUES 
                ('" . $gender . "', '" . $month . "','" . $day . "', '" . $year . "')");
You need the mysql_insert_id function

Code: Select all

$sql = mysql_query("INSERT INTO `users` 
                (`first_name`, `last_name`, `email_address`, `username`, `password`, `signup_date`) VALUES 
                ('" . $first_name . "', '" . $last_name . "','" . $email_address . "', '" . $username . "', '" . $password . "', '" . time() . "')"); 

$autoID = mysql_insert_id();

                $sql = mysql_query("INSERT INTO `basic` 
                (`userid`, `gender`, `month`, `day`, `year`) VALUES 
                ('"'.$autoID."'", '" . $gender . "', '" . $month . "','" . $day . "', '" . $year . "')");
Post Reply