Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Posts
    4

    Question Unanswered: Inserting data across two dependent Tables?

    Hi, first off I'm a newbie to MySQL and databases in general. Second thanks to anyone who even reads this.

    I have two tables that I need to insert data into from one form.

    ORGANIZATION
    ---------------
    address_id
    login
    passcode

    ADDRESS
    ---------
    address_id int(20) PK auto-increment
    address
    city

    The logic is that I need to write to the ADDRESS table which generates a unique address_id. That id then needs to be written to the ORGANIZATION table along with the rest if the data. I would greatly appreciate it if someone would point me in the right direction with just the right keywords I should search on. Thanks in advance.

    i'm'

  2. #2
    Join Date
    Jul 2003
    Posts
    30

    Re: Inserting data across two dependent Tables?

    try something like:

    lock tables;

    INSERT INTO ADDRESS (address, city)
    VALUES ("123 X","New York");

    INSERT INTO ORGANIZATION
    VALUES (last_insert_id(), "X","X");

    unlock tables;

    I would MD5() the password too ...

  3. #3
    Join Date
    Sep 2003
    Posts
    4
    Thanks so much, Gnet. Been so busy learning this stuff that I almost forgot to thank you. This seems so basic now but I hope this helps someone else now.

  4. #4
    Join Date
    Jul 2003
    Posts
    30
    my pleasure ... good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •