【发布时间】:2020-08-01 14:07:03
【问题描述】:
我是 PHP 新手。我创建了一个登录表单,然后填写了所有输入字段。我单击“提交”,然后它说..“列数与第 1 行的值计数不匹配”。有人帮我解决这个问题。我已经有将近 1 周的时间了。这是我的代码。和我的数据库连接。
<?php
$connection = mysqli_connect("localhost","root","","db_violation");
function DBCon(){
try{
$connection = new PDO("mysql:host=localhost;port=3306;dbname=db_violation;","root","");
return $connection;
}catch(PDOException $e){echo "Connection failed: ".$e->getMessage();}
}function DBDiscon(){return $connection = null;}
?>
<?php
include '../../PROCESS/dbconnect/dbconnect.php';
$datauserssystems = json_decode(file_get_contents("php://input"));
$user_firstname = mysqli_real_escape_string($connection, $datauserssystems->user_fname);
$user_middlename = mysqli_real_escape_string($connection, $datauserssystems->user_mname);
$user_lastname = mysqli_real_escape_string($connection, $datauserssystems->user_lname);
$user_address = mysqli_real_escape_string($connection, $datauserssystems->user_address);
$user_positionss = mysqli_real_escape_string($connection, $datauserssystems->user_positions);
$user_age = mysqli_real_escape_string($connection, $datauserssystems->user_age);
$user_username = mysqli_real_escape_string($connection, $datauserssystems->user_uname);
$user_userpass = mysqli_real_escape_string($connection, $datauserssystems->user_pwd);
$tableRows = DBCon()->prepare("SELECT COUNT (*) AS row FROM sb_account");
$tableRows->execute();
$count = $tableRows->fetch();
$count = ($count["row"]+1);
$gain ="SbAdmin";
$encrpt = md5($gain.$user_userpass);
$security = DBCon()->prepare("INSERT INTO sb_account_security VALUES('".$count."','".$encrpt."','".$user_userpass."')")->execute();
$sbuserssssquery = mysqli_query($connection, "SELECT * FROM sb_account WHERE sb_username='$user_username'");
$sbuserssssarray = mysqli_fetch_array($sbuserssssquery);
$sbuserssss = $sbuserssssarray['sb_username'];
if($sbuserssss == $user_username) {
echo "sbtwice";
die();
}
else {
mysqli_query($connection, "INSERT INTO sb_account (sb_firstname,sb_middlename,sb_lastname,sb_fullname,sb_address,sb_position,sb_age,sb_username,sb_password) VALUES ('$user_firstname','$user_middlename','$user_lastname','$user_address','$user_positionss','$user_age','$user_username','$encrpt')");
if(mysqli_affected_rows($connection) > 0) {
echo "AddUserSystem";
die();
}
else {
echo mysqli_error($connection);
die();
}
}
?>
【问题讨论】:
-
永远不要在您的帖子中添加任何登录或数据库凭据!您指定的连接是针对您的本地数据库的,因此无论如何没有人能够通过网络访问它。只是在处理 prod 应用程序时要记住的事情。
-
错误很明显。它说你有比值更多的列。查看您的第二个
INSERT- 您列出了 9 个列名,然后给出 8 个值。还有 - do not usemd5for passwords!!. -
您的代码存在 很多 错误,首先是您同时使用
mysqli和PDO- 使用其中一个,而不是同时使用.然后你使用prepare,但仍然注入值而不是使用参数......DBDiscon()绝对没有做任何事情,因为它创建了一个新的局部变量,将其设置为null并返回它......老实说,这是一团糟。
标签: php