gpt4 book ai didi

php - 在cpanel上将注释插入mysql数据库

转载 作者:行者123 更新时间:2023-11-29 21:47:49 25 4
gpt4 key购买 nike

我试图允许用户在我的网站中插入他们的评论,但它向我显示了此错误

显示的错误是错误:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 ''id'、'name'、'email'、'website'、comment 附近使用的正确语法。 , timestamp , articleid ) 第 1 行的 VALUE

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 ''id', 'name', 'email', 'website', `comment`, `timestamp`, `articleid`) VALUE' at line 1
<?


if( $_POST )
{
$con = mysql_connect("localhost","iluxcoke_myuser","qwert2012");

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("iluxcoke_inmoti6_mysite", $con);

$users_name = $_POST['name'];
$users_email = $_POST['email'];
$users_website = $_POST['website'];
$users_comment = $_POST['comment'];

$users_name = mysql_real_escape_string($users_name);
$users_email = mysql_real_escape_string($users_email);
$users_website = mysql_real_escape_string($users_website);
$users_comment = mysql_real_escape_string($users_comment);


$sql = "SELECT * FROM `comments` LIMIT 0, 30 ";
$sql= "INSERT INTO `comments`('id', 'name', 'email', 'website',
`comment`, `timestamp`, `articleid`) VALUES ( id, '$users_name',
'$users_email', '$users_website', '$users_comment',
'CURRENT_TIMESTAMP ');";

if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
//mysql_query($sql)

echo "<h2>Thank you for your Comment!</h2>";

mysql_close($con);
}
?>

最佳答案

将 ID、姓名、电子邮件和网站上的单引号更改为反引号。另外 CURRENT_TIMESTAMP 不应该用单引号括起来,因为它是 MySQL 属性。

INSERT INTO `comments` (`id`, `name`, `email`, `website`,
`comment`, `timestamp`, `articleid`) VALUES ( $id, '$users_name', '$users_email', '$users_website', '$users_comment', CURRENT_TIMESTAMP);

关于php - 在cpanel上将注释插入mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33957977/

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