Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2002
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I add to 3 different tables in the same query?

    This is the segment of the code:

    <?PHP
    if($Submit){
    //formulate a jobID
    include("jobID.php");
    $conn = db_connect();
    //declare query
    $query = ('INSERT INTO currProjects (id,companyName,contact,phoneNum,email,url,street,
    city,provState,country,postalCode,jobSummary,contr
    actStatus,status) VALUES ("'.$jobID.'","'.$company.'","'.$cont.'","'.$phone.'","'.$Email.'","'.$URL.'","'.$Street.'","'.$City .'","'.$prov.'","'.$Country.'","'.$postal.'","'.$jobSum.'","none","lead"); INSERT INTO contracts (id) VALUES ("'.$jobID.'"); INSERT INTO invoices (id) VALUES ("'.$jobID.'")';
    //execute query
    $result = mysql_query($query);
    }
    ?>

    I know there is an easier way to do this but I just don't know it. Please teach me.

    Thanks

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am not sure on this, but I thing you can do JOIN's for this.

  • #3
    New Coder
    Join Date
    Sep 2002
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Joins?

    I've heard of joins and I think they would be wonderful if I knew how to do them. Can somebody show me what a join would look like for this example and I'd like to understand when you should use them?

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, sorry. On second thought it now seems kind of strange to try and do a join with an insert. Doing 3 inserts at once really ain't that bad. I dont know whaere I am going anymore.


  •  

    Posting Permissions

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