Take the 2-minute tour ×

I am a total newbie for php and mysql. Now I want to create a simple website for practice. I have created two tables named user_info and acct_info.

The primary key for user_info is the user_id. There is another user_id in acct_info as well.

I have relate these two tables by linking the user_id (referenced key is the user_id in user_info, that of acct_info is foreign key). However, when new user register new account on my website, new data will be added into the user_info table, but nothing happened in acct_info table.

Could anyone provide me some advice?

Sorry for not stating the problem clearly. I have created a new user, however, data is added into user_info table but nothing in acct_info table. I thought if I build relationship between these two tables, for example, I create new user, then data like user_id and all those default data should be also added into acct_info table. I wrote php codes in my registration page to add user information into user_info table but I didn't do it to add data into acct_table. If I need to write codes for acct_table, what is the purpose to relate these two tables?

Sorry for asking dummy questions... :)

This is the php code for the data adding part:

if($reachByPOST && $okay == true && $NotExistingUsername == true && $NotExistingEmail == true) {
    $sql = "INSERT INTO user_info SET user_id = '',user_name = '".$_POST['username']."',password = '".$_POST['password']."',email = '".$_POST['email']."'";
    $res = mysql_query($sql);
    $_SESSION['user_id'] = $userid;
    $sql2 = "INSERT INTO acct_info SET user_id = '".$userid."'";
    $res2 = mysql_query($sql2);

However, I got error saying $userid is undifiend...I just have no idea on how to add data into acct_info table...By the way the user_id is auto_increment in user_info table, it is generated automatically, not post input by user.

share|improve this question
Could you post your code where you insert data to the tables –  Breezer Aug 25 '12 at 14:12
What is PHPMyAdmin doing here? My advice, review your php code or post some code excerpt (showing the revelant parts) –  RC. Aug 25 '12 at 14:13
that is because you are not inserting to it, you will also need to insert data there. please post ur code –  DotNet Dreamer Aug 25 '12 at 14:16

1 Answer 1

if you insert in user_info, it has no affect to acct_info.

But if you insert into acct_info, there should exist user_id in user_info(pri key), which will be inserted in acct_info.

Try to insert random data in acct_info.... If you don't have right user_id, you should get error.

share|improve this answer

Your Answer


