插入有外键并希望从另一个表插入的表中

时间:2020-03-12 13:44:12

标签: php mysql visual-studio-code foreign-keys primary-key

您好,我有一个查询要在其中插入一些数据,并且我有一个外键,因为它在那里有主键,所以我希望从另一个表中插入它

这是我的代码:

$con = new mysqli("localhost", "root", "", "company");
$st = $con->prepare("INSERT INTO reservations(customer_id,players_number,res_date) VALUES(?,?,?)");
$st->bind_param("iii", $_POST["players_number"], $_POST["res_date"], $_GET["id"]);
$st->execute();
header('Location: http://localhost/tech/calendar.php');

我要插入的表称为保留,并且customer_id必须来自客户表中的主键 我在此代码下有一个表单,该表单通向同一页面以转到上面的代码

enter image description here

谢谢!

当我转到客户的日历时,我有这个网址

enter image description here

当我按下添加保留按钮时,使用$ _GET方法在URL中具有ID

enter image description here

这是我得到的错误:

enter image description here

很抱歉,如果这不是一个很明确的问题,但是我是新来的,我要完成很多实习工作,而我却拼死了!

0 个答案:

没有答案
相关问题