Web Analytics Made Easy -
StatCounter inserting data into multiple tables - CodingForum

Announcement

Collapse
No announcement yet.

inserting data into multiple tables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • inserting data into multiple tables

    Hi,

    I am bugged by this insert into multiple tables problem. I have searched similar problems on this forum but non seems to work on my issue. My insert code is as follows:

    PHP Code:
    $result 
    mysql_query("INSERT INTO members (id, name,birthdate, age, status, occupation)
        VALUES(NULL, '
    $NAME', '$BDATE', '$AGE', '$STATUS', '$OCCUPATION')");
            
    $result mysql_query("INSERT INTO ed (id, elem, hs, college)
                      VALUES(NULL,'
    $ELEM', '$HS', '$COLLEGE')"); 
    So, basically I have two tables. One is the members table and the other one is the ed table. The insertion query for members table works well. It inserts the data on the table. However, when its time to insert on the next table which is ed, nothing happens. Is their any conflicting syntax or rules that makes my insertion into multiple tables impossible. Please help me out. Thank you in advance.

  • #2
    Try a couple of things ... not sure if these have been mentioned yet.

    1) Don't use $result for both queries.
    Make one $result, and the other $result2 (or something different).

    2) It could be that the first insert has not finished before the 2nd one ...
    like a PHP timeout issue. So, try an "if" statement to force PHP to stay on
    that command until it's 'true' (complete).

    Like this ...
    PHP Code:

    if(mysql_query("INSERT INTO members (id, name,birthdate, age, status, occupation)
        VALUES(NULL, '
    $NAME', '$BDATE', '$AGE', '$STATUS', '$OCCUPATION')")){
    // complete
    }
            
    if(
    mysql_query("INSERT INTO ed (id, elem, hs, college)
                      VALUES(NULL,'
    $ELEM', '$HS', '$COLLEGE')")){
    // complete



    .

    Comment

    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎