简体   繁体   English

插入值在mysqli中不起作用

[英]insert values not working in mysqli

I have created two tables, employee and department. 我创建了两个表,employee和部门。 Now, in the department table, I assigned a foreign key and a PK is assigned for the employee table. 现在,在部门表中,我分配了外键,并为员工表分配了PK。 If view data, Ii can join the table. 如果查看数据,则可以加入表。

How to write the query in PHP for insert and update? 如何在PHP中编写查询以进行插入和更新?

My query: 我的查询:

?php
include "connect.php";
if(isset($_POST["submit"]))
{
    $fname  = $_POST["fname"];
    $dept   = $_POST["dept"];


    $result = mysqli_query($mysqli, "INSERT INTO employee ( fname, department)
            (SELECT fname, department FROM employee LEFT JOIN department ON employee.id=department.dept_id) values ( '$fname', '$dept')");

    if($result)
        {
            echo "<script>alert('New employee register successfully!')</script>";
            echo "<script>window.open('register.php','_self')</script>";
        }
    else 
        {
            echo "<script>alert('something went wrong!')</script>";
        }
    }
?>
$result = mysqli_query($mysqli, "INSERT INTO employee (`fname`, `dept`)
VALUES ('$fname','$dept')");
if($result)
    {
        echo "<script>alert('New employee register successfully!')</script>";
        echo "<script>window.open('register.php','_self')</script>";
    }

// You Forget ( `` ) sign in values //您忘记(``)登录值

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

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