gpt4 book ai didi

php - 添加新用户,不会进入数据库或显示结果

转载 作者:行者123 更新时间:2023-11-30 23:20:52 25 4
gpt4 key购买 nike

我正在尝试使用用户名和密码字段以及一个按钮将新用户输入系统。当我输入凭据时,我根本没有收到任何响应,甚至没有错误消息。

代码如下:

<?php
session_start();
$logged_in = isset($_SESSION['USERNAME']) && $_SESSION['USERNAME'] ?
$_SESSION['USERNAME'] : null;
if(!$logged_in) {
header("location:index.php");
}
include 'dbsettings.php';

// username and password sent from form in login.php
$username=$_POST['username'];
$password=$_POST['password'];

// encrypting password
$encrypted_password=md5($password);

$stmt = $dbh->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 = $dbh->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 admin. <span class='label
label-success'>Success</span>";

//send an email to the user


session_start();
$_SESSION['USERNAME']=$username;
$_SESSION['PASSWORD']=$encrypted_password;

}

}else{
echo $username." is already a supervisor register in the PPM tool. <span class='label label-warning'>Warning</span>";

}
$dbh = null;
?>

这是表单的目标和表单本身:

 <form name="form1" method="post" action="adduser.php" >


<input type="text" placeholder="Username" name="username" id="username">
<input type="password" placeholder="Password" name="password" id="password">
<button class="btn btn-primary addSupervisor" type="button">Add new
user</button>

</form>

你能看出这不起作用的任何原因吗?

最佳答案

如果您的设置以某种方式禁用了它,请添加到顶部以强制出现错误:

error_reporting(E_ALL);
ini_set('display_errors', 1);

而且看起来您正在第二次调用 session_start()(在评论向用户发送电子邮件之后),也应该看看。

关于php - 添加新用户,不会进入数据库或显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15505677/

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