Jump to content

[PHP][MySQL] Inserting in the first tbl doesn't insert in the second tbl.


TAViX

Recommended Posts

Ok, I have 2 tables let's say first one is called batch_info with the following entries: batch_id (Primary Key - PK), trainee_num (FK), nickname (FK), etc,  and passport_id with those entries: passport_id (PK), trainee_num (PK), nickname (PK), etc...

 

As you can see in the first table, batch_id, trainee_num and nickname, are linked to the values from the second table.

 

Now, I have this script that introduce the values in passport_info table, but the problem is that this script doesn't also update/insert the values from trainee_num and nickname also in the batch_info table, even if the entries are linked...

 

MySQL: 

 

batch_info Links to:      trainee_num: dbrev00.passport_info.trainee_num ON DELETE: cascade ON UPDATE: cascade

                                        trainee_num: dbrev00.passport_info.nickname      ON DELETE: cascade ON UPDATE: cascade

 

So my question is, how to update this code in order to have the same values in both tables??

 

    mysql_query("INSERT INTO passport_info 
        (trainee_num, sur_name, given_names, middle_name, nickname)
        VALUES ('".clean($tc)."', '".clean($sn)."', '".clean($gn)."','".clean($mn)."','".clean($nn)."')" )
        or die(mysql_error());

 

 

 

Thanks in advance.

Link to post
Share on other sites

Bottom line: two INSERT queries are needed (well... in your case three - in other words: one per table).

 

However, inserting same data into three tables might indicate that your database design is flawed (i.e. not normalised)

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.