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
4Boredom
Forum Contributor
Posts: 176 Joined: Tue Nov 08, 2005 4:29 pm
Post
by 4Boredom » Mon Aug 21, 2006 12:01 am
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
Post
by GeXus » Mon Aug 21, 2006 12:05 am
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 » Mon Aug 21, 2006 12:08 am
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 21, 2006 12:14 am
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 » Mon Aug 21, 2006 12:21 am
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 » Mon Aug 21, 2006 8:04 am
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 » Wed Aug 23, 2006 10:59 pm
what do you mean by selecting it first
4Boredom
Forum Contributor
Posts: 176 Joined: Tue Nov 08, 2005 4:29 pm
Post
by 4Boredom » Sun Aug 27, 2006 2:22 pm
up ^^^
blackbeard
Forum Contributor
Posts: 123 Joined: Thu Aug 03, 2006 6:20 pm
Post
by blackbeard » Sun Aug 27, 2006 2:35 pm
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 . "')");