2017-05-29 97 views
0

我想在我的表单中插入一个外键值。但没有这样做。在添加FK之前,它已成功添加到数据库中。PHP代码插入外键值

My form. "Empno" is a foreign key to a "compliance table"

Is this coding correct?

+2

将代码片段复制粘贴到此处而不是图像 – Nidhi

+0

<?php error_reporting(0); //创建连接 $ con = mysqli_connect(“localhost”,“root”,“”,“mttiem”); //检查连接 if(mysqli_connect_errno()) echo“无法连接到MySQL:”。 mysqli_connect_error(); } $ c = $ _POST [“date”]; $ d = $ _POST [“time”]; $ e = $ _POST [“module”]; $ f = $ _POST ['category']; $ g = $ _POST ['observation']; $ h = $ _POST [“observer”]; $ i = $ _POST [“empno”]; ('$ c','$ d','$ e','$ f','$','$','$','$','$','$''' $克”, '$ H', '$ I')“; $ result = mysqli_query($ con,$ sql); ?> @Nidhi这样 – FAR

+0

什么是表格模式中的'date'和'time'列的数据类型?@FAR – Nidhi

回答

0

正如你们所指出之前,我添加FK,它被成功添加到数据库中。

当两个表格绑定的关系为foreign key时,在这种情况下,只能在child table中插入那些已存在于parent table中的值。

所以可能是你试图插入的值不存在于父表中。

+0

我尝试先截断表格,然后再插入值。成功〜谢谢 – FAR