dro62273 2014-02-13 05:42
浏览 32
已采纳

在多个提交中将外键存储在PHP中的最佳方法?

I have two tables in my mysql database. Constructed using:

CREATE TABLE Projects(
ID int NOT NULL AUTO_INCREMENT,
ProjectName VARCHAR(30),
Password VARCHAR(30),
Creatorname VARCHAR(30),
PRIMARY KEY(ID) 
);

CREATE TABLE Items 
(
ItemId int NOT NULL AUTO_INCREMENT,
Description VARCHAR(200) NOT NULL,
ProjectId int,
Type VARCHAR(20) NOT NULL,
FileLocation VARCHAR(500),
Link VARCHAR(20000),
PRIMARY KEY (ItemId),
FOREIGN KEY (ProjectId) REFERENCES Projects(Id) ON DELETE CASCADE
);

Using two php forms I want to fill these tables. The first form submits to the second form and adds the details into the projects table. The second form is used to add multiple entries to the items table. So I can have many items for each project. What I wanted to know was, what is the best method to store the ID of the project over multiple submissions? I am retrieving the ID via mysqli_insert_id .

Should I use Session Variables or a cookie? Or should I use some other method entirely?

Please forgive any mistakes as I have limited php/mysql/code knowledge...

  • 写回答

1条回答 默认 最新

  • dtncv04228 2014-02-13 06:06
    关注

    Use a session variable, allows the user to not change the project id by easily editing a cookie. Just need to be sure that cookies are enabled as session variables store the session ID in a cookie.

    Alternatively, could you put two forms together and use some jquery to easily create a dynamic form and submit all the data at once?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?