我试图从两个文本框在数据库中输入值,但是当我提交用户名和密码时,我收到此错误:用户尚未在与系统管理员的数据库检查中输入。
<?php
session_start();
$logged_in = isset($_SESSION['USERNAME']) && $_SESSION['USERNAME'] ?
$_SESSION['USERNAME'] : null;
if(!$logged_in) {
}
error_reporting(E_ALL & ~E_NOTICE);
include 'dbconfig.php';
global $db;
$username=$_POST['username'];
$password=$_POST['password'];
// encrypting password
$encrypted_password=md5($password);
$stmt = $db->prepare("SELECT * FROM user_info WHERE username = ?");
$stmt->execute(array($username));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (! $row){
//add new user to database
$stmt = $db->prepare("INSERT INTO user_info(username, password) VALUES (?,?)");
$params1 = array($username, $encrypted_password);
if (!$stmt ->execute($params1)){
echo "user has not been entered on the database check with administrator of the system.
<span class='label label-important'>Important</span>";
}else{
echo $username." has been added to the database as a supervisor. <span class='label
label-success'>Success</span>";
}
else{
echo $username." is already a user of the system <span class='label label-
warning'>Warning</span>";
}
$db = null;
?>
var_dump($行);返回一个 false bool 值,并且不会将值加载到数据库中。 有任何想法吗?谢谢。
最佳答案
从您的代码中无法完全理解错误在哪里。
但是,
当你在
中遇到错误时if (!$stmt ->execute($params1)){
声明,我认为这是一个与数据库相关的错误。
所以首先检查表中用户名字段的大小是多少。对字段中的用户输入进行最大长度检查。
另外,需要注意的是,md5 密码加密会返回近 30 个字符。因此,将密码字段设置为 50 个字符长是安全的。
也可能有其他原因导致错误,但请先确认上述原因,然后重试。
谢谢
关于PHP mysql : registration returning false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15506579/