Reputation: 59
// 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;
}
}
}
Upvotes: 2
Views: 146
Reputation: 1374
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")
Upvotes: 4