在PHP上显示错误 [英] Display error on php
本文介绍了在PHP上显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//我已经更新了代码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.
这是我的代码php,我的数据是mongodb:
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;
}
}
}
推荐答案
isset
将返回布尔结果,因此,如果要执行该代码块,则需要这样编写:
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")
这篇关于在PHP上显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文