Page 1 of 1

UserId in multiple databases

Posted: Mon Aug 21, 2006 12:01 am
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 . "')");

Re: UserId in multiple databases

Posted: Mon Aug 21, 2006 12:05 am
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 . "')");

Posted: Mon Aug 21, 2006 12:08 am
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

Posted: Mon Aug 21, 2006 12:14 am
by feyd
Did you remember to add the "userid" column to the field list?

Posted: Mon Aug 21, 2006 12:21 am
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?

Posted: Mon Aug 21, 2006 8:04 am
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.

Posted: Wed Aug 23, 2006 10:59 pm
by 4Boredom
what do you mean by selecting it first

Posted: Sun Aug 27, 2006 2:22 pm
by 4Boredom
up ^^^

Re: UserId in multiple databases

Posted: Sun Aug 27, 2006 2:35 pm
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 . "')");