#1
  1. No Profile Picture
    fayadev
    Guest
    Devshed Newbie (0 - 499 posts)
    Hi everybody,

    Who can help me to fix a problem.

    I want to join two tables.

    TABLE_A
    Aid int; //auto increment
    name varchar;

    TABLE_B
    Bid int; //same id as Aid
    Author varchar;

    if ($voegtoe) { // name of button in form

    //add a record ID Aid auto increment

    $sql_A = "INSERT INTO TABLE_A (naam) VALUES
    ('$name')";
    mysql_query($sql_A);

    //Tryin' to get the last ID from TABLE_A
    $result_A = mysql_query("SELECT Aid FROM TABLE_A");

    $objectid= mysql_query($result_A);


    //Tryin' to use Aid From TABLE_A

    $sql_B = "INSERT INTO TABEL B (Bid, author) VALUES
    ('$objectid', '$author')";
    mysql_query($sql_B);

    }

    TABLE_B is not getting the ID from TABLE_A, Why??

    Regards,

    Vin@ic
  2. #2
  3. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    Because you are not getting the last id from table a. Your select will return the first id (actually it returns all but you're only getting the result for the first one.) There's a easier, safer way to do this. Check the php manual for the function mysql_insert_id(). This will do what you want.

    Rod

Similar Threads

  1. insert and update 2 tables
    By welly in forum PHP Development
    Replies: 14
    Last Post: February 23rd, 2004, 07:41 AM
  2. Replies: 1
    Last Post: January 19th, 2004, 11:32 PM
  3. Zip code validation
    By krwyth in forum MySQL Help
    Replies: 2
    Last Post: January 5th, 2004, 01:29 PM
  4. tables get corrupted
    By 90coders in forum MySQL Help
    Replies: 1
    Last Post: December 5th, 2003, 05:23 AM
  5. error - parent key
    By mbonfyre in forum Oracle Development
    Replies: 1
    Last Post: November 29th, 2003, 12:44 PM

IMN logo majestic logo threadwatch logo seochat tools logo