gpt4 book ai didi

php - 列存在时 'field list' 中的未知列

转载 作者:行者123 更新时间:2023-11-29 00:02:31 25 4
gpt4 key购买 nike

我创建了一个数据库,它包含以下内容:

desc users;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| UserID | int(25) | NO | PRI | NULL | auto_increment |
| Username | varchar(65) | YES | | NULL | |
| Fname | varchar(65) | YES | | NULL | |
| Lname | varchar(65) | YES | | NULL | |
| Password | varchar(32) | YES | | NULL | |
| Password1 | varchar(32) | YES | | NULL | |
| EmailAddress | varchar(255) | YES | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

但是,当我运行这段代码时

if($email_exists == false && $Password == $Password1)
{
$sql="INSERT INTO users(u_Username, u_Fname, u_Lname, u_EmailAddress, u_Password)
VALUES('$_POST[$Username]', '$_POST[$Fname]', '$_POST[$Lname]', '$_POST[$EmailAddress]', '$_POST[$Password]')";
echo "<pre>"; print_r($sql); exit;
if(!mysqli_query($link, $sql))
{
#$query = mysqli_query($myConnection, $sqlCommand);
#die (mysqli_error($myConnection));
die('Error: ' . mysqli_error($link));
}
header("location: login.php");
}

我收到这个错误:

INSERT INTO users(u_Username, u_Fname, u_Lname, u_EmailAddress, u_Password)
VALUES('', '', '', '', '')

这里有什么错误?我正在使用 php 和 mysqli。我是新手,但我正在尝试让我的 register.php 文件接受并添加到我的数据库中。

编辑这里是完整代码

<?php 
session_start();
require_once('connect.php');
require_once "utils.php";

if(isset($_POST['submit']))
{
//CHECK EMPTY FORM DATA and SANITIZE
if(!empty($_POST['Username'])&&
!empty($_POST['Fname'])&&
!empty($_POST['Lname'])&&
!empty($_POST['EmailAddress'])&&
!empty($_POST['Password'])&&
!empty($_POST['Password1']))
{
$Username = mysqli_real_escape_string($link,htmlentities($_POST['Username']));
$Fname = mysqli_real_escape_string($link,htmlentities($_POST['Fname']));
$Lname = mysqli_real_escape_string($link,htmlentities($_POST['Lname']));
$Password = mysqli_real_escape_string($link,htmlentities($_POST['Password']));
$Password1 = mysqli_real_escape_string($link,htmlentities($_POST['Password1']));
$EmailAddress = mysqli_real_escape_string($link,htmlentities($_POST['EmailAddress']));
}

else { header("Location: register.php");exit(); }

if(isset($EmailAddress) && !empty($EmailAddress) &&
isset($Password) && !empty($Password))
{
$email_exists = false;

$sql="SELECT * FROM users WHERE EmailAddress='$EmailAddress'";

if($result = mysqli_query($link, $sql))
{
while($record = mysqli_fetch_row($result))
{
if($record = $EmailAddress)
{
$email_exists = true;
}

if($email_exists = true)
{
echo "<div id='reg_error1'>* The Email Used Already Exists! <br></div>";
}
}
}

if($Password != $Password1)
{
echo "<div id='reg_error2'>* Your Password Does Not Match!<br></div>";
}

if($email_exists == false && $Password == $Password1)
{
$sql="INSERT INTO users(Username, Fname, Lname, EmailAddress, Password)
VALUES('{$_POST['$Username']}', '{$_POST['$Fname']}', '{$_POST['$Lname']}', '{$_POST['$EmailAddress']}', '{$_POST['$Password']}')";
echo "<pre>"; print_r($sql); exit;
if(!mysqli_query($link, $sql))
{
#$query = mysqli_query($myConnection, $sqlCommand);
#die (mysqli_error($myConnection));
die('Error: ' . mysqli_error($link));
}
header("location: login.php");
}
echo "<hr>";
}
}

最佳答案

$sql="INSERT INTO users(Username, Fname, Lname, EmailAddress, Password)
VALUES('{$_POST['$Username']}', '{$_POST['$Fname']}', '{$_POST['$Lname']}', '{$_POST['$EmailAddress']}', '{$_POST['$Password']}')";

???

您已经将 POST 变量提取到这些本地变量中,那么为什么要尝试将它们用作 post 数组的索引参数?

 $sql="INSERT INTO users(Username, Fname, Lname, EmailAddress, Password)
VALUES('{$Username'}', '{$Fname}', '{'$Lname}', '{'$EmailAddress'}', '{$Password}')";

如果我对您的代码的编辑有误,比如错误位置的引号,那是因为我从来没有写过这样的查询。 PDO 和准备好的语句或存储过程是我从 2003 年开始使用的,我相信任何不这样做的人都是在自找麻烦。

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

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