gpt4 book ai didi

PHP、MySQL 错误 : Column count doesn’t match value count at row 1

转载 作者:太空宇宙 更新时间:2023-11-03 10:42:39 26 4
gpt4 key购买 nike

我创建了一个注册码电子邮件、用户、密码,当我单击“zr”时将此信息插入数据库,但出现以下错误:

MySQL error: Column count doesn’t match value count at row 1

代码:

include ('config.php');
include('login_css.php');
$error = "";
if (isset($_POST['zr'])){
$date = date("m d Y");
$user_name = strip_tags($_POST['user']);
$user_pass = strip_tags($_POST['pass']);
$user_email = strip_tags($_POST['email']);
$empty = strip_tags($_POST['none']);
$empty.= strip_tags($_POST['none']);
$empty.= strip_tags($_POST['none']);
$day = strip_tags($_POST['day']);
$month = strip_tags($_POST['month']);
$year = strip_tags($_POST['year']);
$dob = "$day/$month/$year";

if ($user_name == "") {
$error = "Firstname cannot be left empty.";
echo $error;
}
else if ($user_pass == "") {
$error = "Lastname cannot be left empty.";
echo $error;
}
else if ($user_email == "") {
$error = "Email cannot be left empty.";
echo $error;
}

//Check the username doesn't already exist
$check_username = mysql_query("SELECT yser FROM users WHERE username='$user_name'");
$numrows_username = mysql_num_rows($check_username);
if ($numrows_username != 0) {
$error = 'That username has already been registered.';
echo $error;
}
else
{
$check_email = mysql_query("SELECT email FROM users WHERE email='$user_email'");
$numrows_email = mysql_num_rows($check_email);
if ($numrows_email != 0) {
$error = 'That email has already been registered.';
echo $error;
}
else
{
//Register the user
$register = mysql_query("INSERT INTO users(user,pass,email) VALUES('','$user_name','$user_pass','$user_email','$date')") or die(mysql_error());
die('Registered successfully!');
}
}
}

?>

<!-- Form Mixin-->
<!-- Input Mixin-->
<!-- Button Mixin-->
<!-- Pen Title-->
<div class="pen-title">
<title>WebooHub - Join</title>
<h1>WebooHub - Join</h1>
</div>
<!-- Form Module-->
<div class="module form-module">
<div class="toggle"><i class="fa fa-times fa-pencil"></i>
</div>
<div class="form">
<h2>Create Your Account</h2>
<form action="u_register" method="POST">



<button>Join Now</button>
</form>
</div>
<div class="cta"><a href="login.php">Login?</a></div>
</div><strong></strong>

最佳答案

错误消息告诉您到底出了什么问题。查看您的 INSERT 语句:

INSERT INTO users(user,pass,email) VALUES('','$user_name','$user_pass','$user_email','$date')

您指定了 3 列,但提供了 5 个值。

要么只提供您要插入的 3 个值:

INSERT INTO users(user,pass,email) VALUES('$user_name','$user_pass','$user_email')

或者指定要为其插入值的 5 列:

INSERT INTO users(someColumn,user,pass,email,someOtherColumn) VALUES('','$user_name','$user_pass','$user_email','$date')

另外,这很重要,您的代码对 SQL 注入(inject)完全开放。这意味着您在盲目地执行用户在您的数据库查询中发送给您的任何代码。请看this ,以及 this .在准备好的语句中使用查询参数,以便将用户输入视为而不是代码


此外,您以纯文本形式存储用户密码。这是严重不负责任的密码处理。请hash user passwords correctly .用户密码应隐藏在单向散列后面,并且永远不可检索,即使您作为系统所有者也不可检索。

关于PHP、MySQL 错误 : Column count doesn’t match value count at row 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35726629/

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