Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: HELP: insert data into 4 mysql tables

  1. #1
    Join Date
    Feb 2006
    Posts
    4,242
    Rep Power
    0

    Post HELP: insert data into 4 mysql tables

    I want to insert data from a html form into 4 tables in a mysql database using php;

    How do I go about it, can it be done with one insert statement?
    |--- www.RealJamaicaEstate.com ™ ---|
    Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
    --- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com

  2. #2
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    nope cannot be done with one insert statement. best you use a stored procedure.

  3. #3
    Join Date
    Feb 2006
    Posts
    4,242
    Rep Power
    0

    Post

    direct me to a tuturial or give me an example because I am kind of new to multiple insert. I only know to insert in one table, but now I have 4 tables and I am stuck;

    I am working with dreamweaver 8. This is what I have:
    PHP Code:
    $queryINSERT INTO table1 (col1,col2,..) VALUES ("value1","value2",..);
    INSERT INTO table2 (col1,col2,..) VALUES ("value1","value2",..);
    INSERT INTO table3 (col1,col2,..) VALUES ("value1","value2",..);
    INSERT INTO table4 (col1,col2,..) VALUES ("value1","value2",..);

    mysql_query($query)or die(mysql_error()); 
    Last edited by Utech22; Aug 1, 2007 at 10:44 AM. Reason: dreamweaver
    |--- www.RealJamaicaEstate.com ™ ---|
    Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
    --- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com

  4. #4
    Join Date
    Feb 2005
    Posts
    85
    Rep Power
    0

    Default

    Quote Originally Posted by Utech22 View Post
    direct me to a tuturial or give me an example because I am kind of new to multiple insert. I only know to insert in one table, but now I have 4 tables and I am stuck;

    I am working with dreamweaver 8. This is what I have:
    PHP Code:
    $queryINSERT INTO table1 (col1,col2,..) VALUES ("value1","value2",..);
    INSERT INTO table2 (col1,col2,..) VALUES ("value1","value2",..);
    INSERT INTO table3 (col1,col2,..) VALUES ("value1","value2",..);
    INSERT INTO table4 (col1,col2,..) VALUES ("value1","value2",..);

    mysql_query($query)or die(mysql_error()); 
    Here is a tutorial : http://www.w3schools.com/php/default.asp

  5. #5
    Join Date
    Feb 2006
    Posts
    4,242
    Rep Power
    0

    Default

    I checked here already :http://www.w3schools.com/php/php_mysql_insert.asp
    I did not find the solution;
    |--- www.RealJamaicaEstate.com ™ ---|
    Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
    --- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com

  6. #6
    Join Date
    Apr 2003
    Posts
    13,270
    Rep Power
    35

    Default

    Quote Originally Posted by Utech22 View Post
    I checked here already :http://www.w3schools.com/php/php_mysql_insert.asp
    I did not find the solution;
    The 4 INSERT statements that you posted is the correct way to insert data into 4 different tables. What else do you want to know?

  7. #7
    Join Date
    Feb 2005
    Posts
    85
    Rep Power
    0

    Default

    Quote Originally Posted by Utech22 View Post
    I want to insert data from a html form into 4 tables in a mysql database using php;

    How do I go about it, can it be done with one insert statement?
    INSERT ALL INTO table1 (name,salary)
    VALUES('Julie','22500')
    INTO table2 (name,salary)
    VALUES('Julie','22500')
    INTO table3 (name,salary)
    VALUES('Julie','22500')
    INTO table4 (name,salary)
    VALUES('Julie','22500');


    for more info check this out: http://www.tizag.com/sqlTutorial/sqlinsert.php
    Last edited by ToxXxic; Aug 1, 2007 at 03:32 PM.

  8. #8
    Join Date
    Feb 2006
    Posts
    4,242
    Rep Power
    0

    Default

    Quote Originally Posted by Arch_Angel View Post
    The 4 INSERT statements that you posted is the correct way to insert data into 4 different tables. What else do you want to know?
    not working for me:

    This is what I have before I revise it:
    PHP Code:
    $query  INSERT INTO name (fname,lname,..) VALUES ("Mary","Blige",..); 
    $query1 INSERT INTO address (town,parish,..) VALUES ("Mona","St. Andrew",..); 
    $query2 INSERT INTO phone (cell,fax,..) VALUES (8760001234,8769230002,..); 
    $query3 INSERT INTO computer (brand,type,..) VALUES ("Dell","Laptop",..); 
     
    mysql_query($query)or die(mysql_error());
    mysql_query($query1)or die(mysql_error());
    mysql_query($query2)or die(mysql_error());
    mysql_query($query3)or die(mysql_error()); 
    I'll still not getting it
    |--- www.RealJamaicaEstate.com ™ ---|
    Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
    --- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com

  9. #9
    Join Date
    Feb 2006
    Posts
    4,242
    Rep Power
    0

    Default

    Quote Originally Posted by ToxXxic View Post
    INSERT ALL INTO table1 (name,salary)
    VALUES('Julie','22500')
    INTO table2 (name,salary)
    VALUES('Julie','22500')
    INTO table3 (name,salary)
    VALUES('Julie','22500')
    INTO table4 (name,salary)
    VALUES('Julie','22500');


    for more info check this out: http://www.tizag.com/sqlTutorial/sqlinsert.php
    GETTING AN ERROR :'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use'
    |--- www.RealJamaicaEstate.com ™ ---|
    Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
    --- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com

  10. #10
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    You say it is not working for you, but what errors do you get? Also I noticed you are using integers for phone numbers. You should think of using a type of VARCHAR for that information as a user can enter a number like '876-555-1000' which would fail in insert into an integer column.

Posting Permissions

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