您的SQL语法有误;检查与您的MariaDB服务器版本相对应的手册以使用nea的正确语法 [英] You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use nea

查看:212
本文介绍了您的SQL语法有误;检查与您的MariaDB服务器版本相对应的手册以使用nea的正确语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误 //错误

将错误插入到new_comp_reg(phno,全名,地址,dept,desc)值(``,'','','','') 您的SQL语法有误;检查与您的MariaDB服务器版本相对应的手册,以在第1行的'desc)VALUES('','','','',''))'附近使用正确的语法

ERRORINSERT INTO new_comp_reg (phno , fullname , address , dept , desc) VALUES ('','','','','') You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'desc) VALUES ('','','' ,'','')' at line 1

PHP

<?php

    $servername = 'mysql.hostinger.in';
    $username = '';
    $password = '';
    $dbname = 'u424351292_icrcm';

    if(isset($_POST['submit']))
    {
        $phone_no = $_POST['phno'];
        $full_name = $_POST['fullname'];
        $location = $_POST['address'];
        $department = $_POST['dept'];
        $description = $_POST['desc'];
    }

        $conn = new mysqli($servername,$username,$password,$dbname);

        if($conn->connect_error)
        {
            die("Connection Failed" . $conn->connect_error);
        }

        $sql = "INSERT INTO new_comp_reg (phno , fullname , address , dept , desc)  VALUES ('$phone_no' , '$full_name' , '$location' , '$department' , '$description')";

        if($conn->query($sql) === TRUE)
        {
            echo "Complaint Registered";
        }
        else
        {
            echo "ERROR".$sql."<br>".$conn->error;
        }

    $conn->close();
    ?>

//错误

将错误插入到new_comp_reg(phno,全名,地址,dept,desc)值(``,'','','','') 您的SQL语法有误;检查与您的MariaDB服务器版本相对应的手册,以在第1行的'desc)VALUES('','','','',''))'附近使用正确的语法

ERRORINSERT INTO new_comp_reg (phno , fullname , address , dept , desc) VALUES ('','','','','') You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'desc) VALUES ('','','' ,'','')' at line 1

推荐答案

desc

desc is a reserved keyword in MySQL and needs to be escaped by backticks.

INSERT INTO new_comp_reg (..., `desc`)  VALUES (...)

或将您的列名更改为description.

顺便说一句,您没有逃避可能导致语法错误和SQL注入的用户输入.使用准备好的语句.

BTW you are not escaping your user input which could lead to syntax errors and SQL injections. Use Prepared Statements.

这篇关于您的SQL语法有误;检查与您的MariaDB服务器版本相对应的手册以使用nea的正确语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆