duankanyi6539 2015-05-07 17:31
浏览 17

在php上显示错误

// I have updated my code php and improve my question

i have a login form, and when i wrong password i don't have this error:

"your are not register or your password is wrong !"

I have nothing, there is nothing that appears.

this is my code php, my data is mongodb :

<?php



if (isset($_POST['submit']) && $_POST['submit'] == "Login"){
    $username = strip_tags($_POST['username']);
    $password = strip_tags($_POST['password']);
    $error    = array();
    // Username Validation
    if (empty($username)) {
         $error[] = " <h2>  complete username </h2>";
    }
    if (empty($password)) {
         $error[] = " <h2> complete password</h2> ";
    }

        // connexion data
    if (count($error) == 0)
    {
        $host               = 'localhost';
        $database_name      = 'Projet';
        $database_user_name = '';
        $database_password  = '';
        $connection         = new MongoClient();

        if ($connection)
        {
            // select data
            $database = $connection->$database_name;

            // Select collection
            $collection = $database->reg_users;
            $user_data  = array(
                "username" => $username,
                "password" => md5($password)
            );
            $result     = $collection->find($user_data);
            if ($result>0)
            {
                header("Location: Articles.php");
                foreach ($result as $doc)
                 {
                    $_SESSION['email']    = $doc['email'];
                    $_SESSION['username'] = $doc['username'];
                 }

             }else{

                      $error[] = " <h2> your are not register or your password is wrong !  </h2>";
                }

            } else {
                      $error[] = " no mongodb connection";
                }
        }  

         if(count($error) > 0) 
        {
             foreach($error as $e)
             {
                echo $e;
             }
        }
}
  • 写回答

1条回答 默认 最新

  • dongluo1853 2015-05-07 17:42
    关注

    isset will return a boolean result and therefor needs to be written more like this if you want that code block to execute:

    if (isset($_POST['submit']) && $_POST['submit'] == "Login")
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂