$ _GET [],添加或更新子行:外键约束失败

时间:2019-06-13 20:03:22

标签: php mysql

我正在从车辆表购买车辆。实际上,我有列出已列出车辆的表格,并且在每一行中(车辆牌照旁边)都有购买链接,应该将“选择的车辆牌照”“发送”到购买表格中。当我单击购买时,出现错误:...无法添加或更新子行:外键约束失败

vehicles.php

...
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo '<tr><td>'.$row["id_vehicle"].'</td>';
        echo '<td>'.$row["type"].'</td>';
        echo '<td>'.$row["set_up"].'</td>';
        echo '<td>'.$row["capacity"].'</td>';
        echo '<td><a href="order.php?id_vehicle='.$row["id_vehicle"].'">Purhcase</a></td>';
...

order.php

...
$id_vehicle = $_GET['id_vehicle'] ?? ''; //doesn't work
// $id_vehicle = "AMT1365"; //works
$departure_place=$_POST['departure_place'] ?? '';
$arrival_place=$_POST['arrival_place'] ?? '';
$order_info=$_POST['order_info'] ?? '';
$id_user=3;
$sql_form = "INSERT INTO orders(departure_place, arrival_place, order_info, id_user, id_vehicle)
            VALUES('$departure_place', '$arrival_place', '$order_info', '$id_user', '$id_vehicle')";

从代码中可以看到,问题出在order.php文件中。当我尝试获取$ id_vehicle并将其插入表顺序时,出现上述错误。但是,当我手动插入一些id_vehicle(存在于餐桌车辆中)时,一切正常,并且购买已成功按餐桌顺序写入。

0 个答案:

没有答案