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

时间:2013-03-19 16:53:39

标签: php mysql database forms

我正在尝试使用用户名和密码字段以及按钮向系统输入新用户。当我输入凭证时,我根本得不到任何回复,甚至没有错误消息。

以下是代码:

<?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>

你能看出为什么这不起作用的原因吗?

1 个答案:

答案 0 :(得分:0)

添加到顶部以强制错误,因为您的设置已以某种方式禁用它:

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

看起来你第二次调用session_start()(在评论发送电子邮件给用户之后),也应该看一下。