gpt4 book ai didi

php - 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,了解使用 nea 的正确语法

转载 作者:行者123 更新时间:2023-12-04 13:48:54 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Syntax error due to using a reserved word as a table or column name in MySQL

(1 个回答)


9 个月前关闭。




我收到此错误
//错误

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 ('','','','','') 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

最佳答案

descreserved keyword in MySQL并且需要通过反引号进行转义。

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

或将您的列名更改为 description例如。

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

关于php - 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,了解使用 nea 的正确语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34321222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com