SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Now available in Orange Tijmen's Avatar
    Join Date
    Jul 2004
    Location
    The Netherlands
    Posts
    1,469
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Insert data into 2 tables with 1 query fails

    I found 2 old threads on how to insert data into 2 tables with 1 query. Both of them said that i should seperate the inserts with a ;. But i must be doing something wrong, because it comes up with an error like this ".....right syntax to use near '; INSERT INTO eiland_details"

    What am i doing wrong? It's possible, right? To insert data into multiple tables with 1 query?

    Code:
    $query = "
    INSERT 
      INTO sub_pages 
        (mainpage_id, intro_text) 
      VALUES 
        ('$main_data->mainpage_id','$sub_intro');
    INSERT 
      INTO eiland_details 
        (inwoners, oppervlakte)
      VALUES
        ('$detail_inwoners',$detail_oppervlakte')";
    Travel Photos on Flickr - Twitter

    “Never give up. Never surrender”

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing this is PHP from the variables. mysql_query() only sends a single query. You need to run two queries -- one for each INSERT.

  3. #3
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i assume this is php? you can't do two inserts like that. mysql_query() only allows one statement at a time.

  4. #4
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will have to call mysql_query() separately for each of the queries, or switch to mysqli and use mysqli_multi_query().


Bookmarks

Posting Permissions

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