简体   繁体   English

将记录插入到多个表中没有通用ID

[英]Inserting Record into multiple tables No Common ID

OK so I have two tables, MEDIA and BUSINESS. OK,所以我有两个表,MEDIA和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. MEDIA有一行biz_id,它是BUSINESS的ID。 So MEDIA is really a part of BUSINESS. 因此,MEDIA实际上是业务的一部分。 HOW do I insert/add these into their tables without a common ID because I haven't yet made the record for business? 由于尚未建立业务记录,如何在没有公共ID的情况下将它们插入/添加到它们的表中?

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 . 您已定义的关系只有在首先插入business然后使用其ID填充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. 插入业务,找到您刚刚创建的ID,然后在biz_id字段中插入具有该ID的媒体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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