Php 无法在数据库中插入值

Php 无法在数据库中插入值,php,mysql,sql,Php,Mysql,Sql,有人能帮我吗? 我试图在数据库中添加一些值,但我无法插入它,我不知道原因是什么?你能帮忙吗? 我有正确的html代码,我的意思是我用正确的名字定义了所有的输入,我不知道为什么我不能在这里发布它 我的php代码如下: <?php require_once("../../../include/admin/ad_ovhead.php"); require_once("../../../lib/connection.php"); if (isset($_POST["add"])) { /

有人能帮我吗? 我试图在数据库中添加一些值,但我无法插入它,我不知道原因是什么?你能帮忙吗? 我有正确的html代码,我的意思是我用正确的名字定义了所有的输入,我不知道为什么我不能在这里发布它 我的php代码如下:

<?php 
require_once("../../../include/admin/ad_ovhead.php");
require_once("../../../lib/connection.php");
if (isset($_POST["add"])) {
    //lấy thông tin từ các form bằng phương thức POST
    $tend_an = $_POST["tend_an"];
    $ngaybd = $_POST["ngaybd"];
    $ngaykt = $_POST["ngaykt"];
    $mieuta = $_POST["mieuta"];
    if ($tend_an == "" || $ngaybd == "" || $ngaykt == "") {
    echo '<h4 align=center style="color: red;">Vui lòng nhập đầy đủ thông tin</h4>';
    }else if($mieuta ==""){
    //thực hiện việc lưu trữ dữ liệu vào db
    $sql = "INSERT INTO projects(
    tend_an,
    ngaybd,
    ngaykt
    ) VALUES (
    '$tend_an',
    '$ngaybd',
    '$ngaykt'
    )";
    // thực thi câu $sql với biến conn lấy từ file connection.php
    mysqli_query($conn,$sql);
    header('Location:proj_management.php');
    }else{
        //thực hiện việc lưu trữ dữ liệu vào db
        $sql2 = "INSERT INTO projects(
        tend_an,
        ngaybd,
        ngaykt,
        mieuta
        ) VALUES (
        '$tend_an,
        '$ngaybd',
        '$ngaykt',
        '$mieuta'
        )";
        mysqli_query($conn,$sql2);
        header('Location:proj_management.php');
    }
}

如果要从变量中插入值,请删除变量中的双引号

如果要在变量中声明插入查询字符串, 按如下方式声明插入查询字符串:

$sql = 'INSERT INTO projects(
        `tend_an`,
        `ngaybd`,
        `ngaykt`
        ) VALUES ('
        .$tend_an.','
        .$ngaybd.','
        .$ngaykt.',
        )';

从不直接插入post值,这会导致SQL注入攻击。另外,请始终监视
mysqli\u query()
的返回值,如
INSERT-INTO projects(`tend\u an`、`ngaybd`、`ngaykt`、`mieuta`)
'$tend\u an、
值(`tend\u an`、`ngaybd`、`ngaykt`、`mieuta`)的末尾缺少一个引号执行SQL查询后检查错误