I spent a few hours looking on google and the neowin forums too, and nothing that could really help me...
I have a table called USERS, and another table called SELLER, BUYER,
I have in my USERS table id (auto_increment), username, password
in the SELLER and BUYER table I have id (auto_increment), user_id (being referenced to `id` from the USERS table), first_name, last_name
ok so my question is... now what?
when a user registers will everything be automatic?
I have the registration script working to register my users, so I can make entries into the USERS table without a problem, but now how do I use the other tables with the foreign_keys?
my users have the ability to enter information into a form and have it be saved into either SELLER or BUYER but as of right now I get an error
Insertion Failed: Cannot add or update a child row: a foreign key constraint fails (`list_`.`seller`, CONSTRAINT `seller_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`))
mysql_query($sql, $link) or die ("Insertion Failed: " . mysql_error());
I really don't know how this works, I can work without using foreign_keys and just automatically create entry rows and have the id = user_id from a session variable but I'm trying to have something
automatic put into place and learn from it.
can someone give me some help on the proper usage and perhaps a real world example that I can study and learn from using php+sql queries and how the sql database will know which user is logged on and how to make records for that particular user.
Question
saiya
Hey guys,
I spent a few hours looking on google and the neowin forums too, and nothing that could really help me...
I have a table called USERS, and another table called SELLER, BUYER,
I have in my USERS table id (auto_increment), username, password
in the SELLER and BUYER table I have id (auto_increment), user_id (being referenced to `id` from the USERS table), first_name, last_name
ok so my question is... now what?
when a user registers will everything be automatic?
I have the registration script working to register my users, so I can make entries into the USERS table without a problem, but now how do I use the other tables with the foreign_keys?
my users have the ability to enter information into a form and have it be saved into either SELLER or BUYER but as of right now I get an error
Insertion Failed: Cannot add or update a child row: a foreign key constraint fails (`list_`.`seller`, CONSTRAINT `seller_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`))
my query is:
$sql = "INSERT INTO `seller` (`first_name`, `last_name`, `prop_address`, `city`, `zip`, `cell_phone`, `home_phone`, `other1`, `other2`)
VALUES ('$fName', '$lName', '$address', '$city', '$zip', '$cell', '$home', '$other1', '$other2')";
mysql_query($sql, $link) or die ("Insertion Failed: " . mysql_error());
I really don't know how this works, I can work without using foreign_keys and just automatically create entry rows and have the id = user_id from a session variable but I'm trying to have something
automatic put into place and learn from it.
can someone give me some help on the proper usage and perhaps a real world example that I can study and learn from using php+sql queries and how the sql database will know which user is logged on and how to make records for that particular user.
thanks guys
Link to comment
Share on other sites
1 answer to this question
Recommended Posts