简体   繁体   中英

Inserting Record into multiple tables No Common ID

OK so I have two tables, MEDIA and BUSINESS. I want it set up so the forms to input into them are on the same page. MEDIA has a row that is biz_id that is the id of BUSINESS. So MEDIA is really a part of BUSINESS. HOW do I insert/add these into their tables without a common ID because I haven't yet made the record for business?

I'm sorry I didn't really word this very much... You might need more clarification to answer properly and I'll be glad to give any more info. Any help would be greatly appreciated, thanks!

Here is my code for the addbusiness( i dont yet have the media insert set up just inserting the business)`

    $sql="INSERT INTO business (name, phone, city, zipcode, description, dateadded, website, address1, other2, payment_options, Products, email,cat1,cat2,cat3)
    VALUES
    ('$companyname','$phone','$city','$zipcode','$description',curdate(),'$website','$address','$other','$payment','$products','$email','$select1','$select2','$select3')";

    if (!mysql_query($sql,$link))
      {
      die('Error: ' . mysql_error());
      }
    echo "";

    mysql_close($link);

}

    ?>`

Your order of operations makes this sort of relationship impossible.

The relationship as you've defined it can only be created if you insert the business first, then use its id to populate the row in media .

Do multiple queries from the script that processes the form. Insert the business, find what ID you just created, then insert the media with that ID in the biz_id field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM