gpt4 book ai didi

php - Mysql错误 'w'中的未知列 'field list'

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

您好,我是 PhP 新手,正在尝试学习一些东西。所以我试图进行“简单”注册,以开始学习向数据库添加和提取信息的基础知识。我有以下代码,但是当我将信息添加到字段并按提交时,我会收到此错误 return Unknown column 'w' in 'field list'“w”位于名字字段

<?php
include('db.php');
if(isset($_POST['submit'])){
//Perform Verifications

$pass = $_POST['password'];
$cpass = $_POST['confirmpassword'];

if($pass == $cpass)
{
//carry on
$name = mysql_escape_string($_POST['firstname']);
$uname = mysql_escape_string($_POST['username']);
$pass = mysql_escape_string($_POST['password']);
$cpass = mysql_escape_string($_POST['password']);

mysql_query("INSERT INTO `users`(`id`, `firstname` , `username` , `password` ) VALUES (NULL, `$name`, `$uname` ,`$pass`)") or die(mysql_error());

}
else
{
echo "Sorry your passwords do not Match.<br />";
exit();
}

}else{
$form = <<<EOT
<form action="" method="POST" >
Full Name <input type="text" name="firstname" /> <br />
Username: <input type="text" name="username" /> <br />
Password: <input type="password" name="password" /> <br />
Confirm Password: <input type="password" name="confirmpassword" /> <br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;

echo $form;
}


?>

在 db.php 中我只有连接数据库的代码

最佳答案

您必须在中使用引号,而不是反引号

 mysql_query("INSERT INTO `users`(`id`, `firstname` , `username` , `password` ) VALUES (NULL, '".$name."', '".$uname."' ,'".$pass."')") or die(mysql_error());

如果您的id是自动增量字段,则将其从查询中删除

关于php - Mysql错误 'w'中的未知列 'field list',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33317740/

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