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(您的 SQL 语法有错误;查看与您的 MariaDB 服务器版本相对应的手册,了解使用 nea 的正确语法)
问题描述
我收到此错误//错误
ERRORINSERT INTO new_comp_reg (phno , fullname , address , dept , desc) VALUES ('','','','','')您的 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();
?>
//错误
ERRORINSERT INTO new_comp_reg (phno , fullname , address , dept , desc) VALUES ('','','','','')您的 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 是一个 MySQL 中的保留关键字,需要用反引号转义.
desc is a reserved keyword in MySQL and needs to be escaped by backticks.
INSERT INTO new_comp_reg (..., `desc`) VALUES (...)
例如,或者将您的列名更改为 description.
or change your column name to description for instance.
顺便说一句,您没有转义您的用户输入,这可能导致语法错误和 SQL 注入.使用准备好的语句.
BTW you are not escaping your user input which could lead to syntax errors and SQL injections. Use Prepared Statements.
这篇关于您的 SQL 语法有错误;查看与您的 MariaDB 服务器版本相对应的手册,了解使用 nea 的正确语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您的 SQL 语法有错误;查看与您的 MariaDB 服务器版本相对应的手册,了解使用 nea 的正确语法
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
