我正在尝试从两个文本框在数据库中输入值,但是当我提交用户名和密码时,我收到此错误:尚未在数据库中输入用户,请与系统管理员检查。
<?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); 返回一个错误的布尔值,它不会将值加载到数据库中。有任何想法吗?谢谢。