本文介绍了sql查询中的PHP / SQL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是自学php / Mysql。我写了下面的代码



$ con = mysqli_connect(localhost,mangala,abc123,my_db);

//检查连接

if(mysqli_connect_errno())

{

echo无法连接到MySQL:。 mysqli_connect_error();

}



$ sql =INSERT INTO groups(Desc)VALUES('$ _ POST [desc]') ;



if(!mysqli_query($ con,$ sql))

{

die('错误:'。mysqli_error($ con));

}

echo已添加1条记录;



mysqli_close($ con);

?>



当我用HTML调用这个php文件时,显示以下错误



错误:你有错误在你的SQL语法中;查看与您的MySQL服务器版本对应的手册,以便在第1行的'Desc)VALUES('Desktop')附近使用正确的语法



任何人都可以帮助我?

I am self learning php/Mysql. I wrote the following code

$con=mysqli_connect("localhost","mangala","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="INSERT INTO groups(Desc) VALUES('$_POST[desc]')";

if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";

mysqli_close($con);
?>

When I call this php file in HTML, shows following error

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Desc) VALUES('Desktop')' at line 1

anyone can help me?

推荐答案




这篇关于sql查询中的PHP / SQL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 15:47