简体   繁体   English

PHP mysql:注册返回false

[英]PHP mysql: registration returning false

I am trying to enter values in the database from two textboxes yet when I submit the username and password i get this error: user has not been entered on the database check with administrator of the system. 我试图从两个文本框中输入数据库中的值,但是当我提交用户名和密码时出现此错误:未在数据库中输入用户信息,请与系统管理员联系。

<?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($row); var_dump($ row); returns a false boolean and it will not load the values into the database. 返回一个错误的布尔值,并且不会将这些值加载到数据库中。 Any ideas? 有任何想法吗? thanks. 谢谢。

From your code it is not fully understandable where is the error. 从您的代码无法完全理解错误在哪里。

But, 但,

as you get error in 当你得到错误

if (!$stmt ->execute($params1)){

statement, I assume that it is a database related error. 语句,我认为这是与数据库相关的错误。

So first check what is the size of username field in the table. 因此,首先检查表中用户名字段的大小。 make a maxlength checking in user input against the field. 根据字段在用户输入中进行最大长度检查。

Also, to note, a md5 password encryption returns near 30 characters. 另外,需要注意的是,md5密码加密将返回近30个字符。 So it is safe to make your password field 50 char long. 因此,将密码字段的长度设置为50个字符是安全的。

Also there may be other causes for the error, but please confirm those above first and try it again. 另外,可能还有其他导致错误的原因,但请先确认上述原因,然后重试。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM