gpt4 book ai didi

mysql - SQL语法错误;查看与您的 MySQL 服务器版本对应的手册

转载 作者:可可西里 更新时间:2023-11-01 07:10:22 25 4
gpt4 key购买 nike

HTML代码

<!DOCTYPE html>
<html>
<head>
<style>
#right
{
margin-top:109px;
margin-right:225px;
}
#button
{
margin-right:;
margin-top:22px;
}
</style>
</head>
<body>
<div id="total" style="width:1350px">
<div id="top" style="width:1350px;height:69px;background-image:url('top.png');float:;"></div>
<div id="body" style="width:1350px;height:570px;background-image:url('body.jpg');float:;">
<div id="right" style="background-color:;height:283px;width:320px;float:right;">
<form action="new.php" method="post" >
<input type="text" name="username" value="" size="37" placeholder="username"style="height:20px"><br><br>
<pre><input type="password" name="password" value="" size="37" placeholder="password"style="height:20px">
<div id="button"><input type="image" name="" value="submit" src="button.png" /> <input type="checkbox" value="check"><br></pre>
</div>
</form>
</div>
</div>
<div id="footer" style="width:1350px;height:33px;background-image:url('footer.png');clear:both;"></div>
</div>
</body>
</html>

我的 PHP 代码

<?php
$con=mysqli_connect("localhost","prabha","prabha","prabha");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="INSERT INTO table (username, password)
VALUES
('$_POST[username]','$_POST[password]')";

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

mysqli_close($con);
?>

当我输入用户名后点击提交按钮时:prabha密码:passwordofprabha

它显示以下错误。请修复我的代码。

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 'table (username, password) VALUES ('prabha','passwordofprabha')' at line 1

最佳答案

对 MYSQL 保留字使用 ` 反引号...

表名“table”是MYSQL的保留字...

所以你的查询应该如下...

$sql="INSERT INTO `table` (`username`, `password`)
VALUES
('$_POST[username]','$_POST[password]')";

关于mysql - SQL语法错误;查看与您的 MySQL 服务器版本对应的手册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21509026/

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