I want to retrieve one admin to login depends on his username and password but nothing is returned?












0















I am trying to make login function which it takes two arguments username and password but when I check and use this function on login.php file if any value has returned from this function but it do not give me anything.



this is post request and all login file



 <?php 
include "inc/header.php";
include "inc/functions.php";

if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST["admin_login"])) {

$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);

$admin = get_admin_login($username, $password);

if(! session_id()){
session_start();
}
if(! empty($admin)) {
if($admin['username'] == $username) {
if($admin['password'] == $password) {
$_SESSION['msg'] = "Welcome Again " . $username;
redirect("index.php");
}else {
$_SESSION['error_msg'] = "Wrong Password";
redirect("login.php");
}
}else {
$_SESSION['error_msg'] = "Wrong Username";
redirect("login.php");
}
}else {
$_SESSION['error_msg'] = "Wrong Login, Check your Username and Password";
redirect("login.php");
}
}
}
?>


<div class="login-alerts">
<?php if(! session_id()) {
session_start();
}
if(! empty($_SESSION['error_msg'])) {
echo "<div class='alert alert-danger'>";
echo $_SESSION['error_msg'];
echo "</div>";
$_SESSION['error_msg'] = "";
}
if(! empty($_SESSION['msg'])) {
echo "<div class='alert alert-success'>";
echo $_SESSION['msg'];
echo "</div>";
$_SESSION['msg'] = "";
}
?>
</div>
<div class="form">
<div class="form-header">
<h3 class="text-center">Welcome to <span style="color: #b30b0b">Z</span>Blog</h3>
</div>
<div class="form-body">
<form class="form" action="login.php" method="POST" >
<div class="form-group">
<span class=""></span>
<input type="text" name="username" class="form-control" placeholder="Username" required autocomplete="off" >
</div>
<div class="form-group">
<span class=""></span>
<input type="password" name="password" class="form-control" placeholder="Password" required autocomplete="off">
</div>
<div class="form-group">
<input style="float: right;" type="submit" name="admin_login" class="btn btn-default" value="Login" >
<a href="" style="float: left;">Forgot your password?</a>
</div>
</form>
</div>

</div>

<?php include "inc/footer.php"; ?>


function



function get_admin_login($username, $password) {
include "connect.php";
$sql = "SELECT id, username, password FROM admins WHERE username = ? && password = ? ";
try {
$result = $con->prepare($sql);
$result->bindValue(1,$username, PDO::PARAM_STR);
$result->bindValue(2,$password, PDO::PARAM_STR);

$result->execute();
return $result->fetchAll(PDO::FETCH_ASSOC);
}catch(Exception $e) {
echo "Error: ". $e->getMessage(). "n";
return false;
}


}



It always gives me this error ( Wrong Login, Check your Username and Password )
which means that $admin is empty. thanks










share|improve this question























  • Did you check if you receive correctly the fields of username and password? Try echo ... these fields. Make a debugging.

    – Vasilis Greece
    Jan 19 at 18:45













  • Never store passwords in clear text! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Jan 19 at 18:58











  • Why do you sanitize password?

    – Dharman
    Jan 19 at 18:59











  • Vasilis Greece , when I echo username and password nothing appear in the page

    – Ebrahem Samer
    Jan 19 at 19:04











  • Does this return an array of results or just one row ? return $result->fetchAll(PDO::FETCH_ASSOC);

    – Matthew Page
    Jan 19 at 19:06
















0















I am trying to make login function which it takes two arguments username and password but when I check and use this function on login.php file if any value has returned from this function but it do not give me anything.



this is post request and all login file



 <?php 
include "inc/header.php";
include "inc/functions.php";

if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST["admin_login"])) {

$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);

$admin = get_admin_login($username, $password);

if(! session_id()){
session_start();
}
if(! empty($admin)) {
if($admin['username'] == $username) {
if($admin['password'] == $password) {
$_SESSION['msg'] = "Welcome Again " . $username;
redirect("index.php");
}else {
$_SESSION['error_msg'] = "Wrong Password";
redirect("login.php");
}
}else {
$_SESSION['error_msg'] = "Wrong Username";
redirect("login.php");
}
}else {
$_SESSION['error_msg'] = "Wrong Login, Check your Username and Password";
redirect("login.php");
}
}
}
?>


<div class="login-alerts">
<?php if(! session_id()) {
session_start();
}
if(! empty($_SESSION['error_msg'])) {
echo "<div class='alert alert-danger'>";
echo $_SESSION['error_msg'];
echo "</div>";
$_SESSION['error_msg'] = "";
}
if(! empty($_SESSION['msg'])) {
echo "<div class='alert alert-success'>";
echo $_SESSION['msg'];
echo "</div>";
$_SESSION['msg'] = "";
}
?>
</div>
<div class="form">
<div class="form-header">
<h3 class="text-center">Welcome to <span style="color: #b30b0b">Z</span>Blog</h3>
</div>
<div class="form-body">
<form class="form" action="login.php" method="POST" >
<div class="form-group">
<span class=""></span>
<input type="text" name="username" class="form-control" placeholder="Username" required autocomplete="off" >
</div>
<div class="form-group">
<span class=""></span>
<input type="password" name="password" class="form-control" placeholder="Password" required autocomplete="off">
</div>
<div class="form-group">
<input style="float: right;" type="submit" name="admin_login" class="btn btn-default" value="Login" >
<a href="" style="float: left;">Forgot your password?</a>
</div>
</form>
</div>

</div>

<?php include "inc/footer.php"; ?>


function



function get_admin_login($username, $password) {
include "connect.php";
$sql = "SELECT id, username, password FROM admins WHERE username = ? && password = ? ";
try {
$result = $con->prepare($sql);
$result->bindValue(1,$username, PDO::PARAM_STR);
$result->bindValue(2,$password, PDO::PARAM_STR);

$result->execute();
return $result->fetchAll(PDO::FETCH_ASSOC);
}catch(Exception $e) {
echo "Error: ". $e->getMessage(). "n";
return false;
}


}



It always gives me this error ( Wrong Login, Check your Username and Password )
which means that $admin is empty. thanks










share|improve this question























  • Did you check if you receive correctly the fields of username and password? Try echo ... these fields. Make a debugging.

    – Vasilis Greece
    Jan 19 at 18:45













  • Never store passwords in clear text! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Jan 19 at 18:58











  • Why do you sanitize password?

    – Dharman
    Jan 19 at 18:59











  • Vasilis Greece , when I echo username and password nothing appear in the page

    – Ebrahem Samer
    Jan 19 at 19:04











  • Does this return an array of results or just one row ? return $result->fetchAll(PDO::FETCH_ASSOC);

    – Matthew Page
    Jan 19 at 19:06














0












0








0








I am trying to make login function which it takes two arguments username and password but when I check and use this function on login.php file if any value has returned from this function but it do not give me anything.



this is post request and all login file



 <?php 
include "inc/header.php";
include "inc/functions.php";

if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST["admin_login"])) {

$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);

$admin = get_admin_login($username, $password);

if(! session_id()){
session_start();
}
if(! empty($admin)) {
if($admin['username'] == $username) {
if($admin['password'] == $password) {
$_SESSION['msg'] = "Welcome Again " . $username;
redirect("index.php");
}else {
$_SESSION['error_msg'] = "Wrong Password";
redirect("login.php");
}
}else {
$_SESSION['error_msg'] = "Wrong Username";
redirect("login.php");
}
}else {
$_SESSION['error_msg'] = "Wrong Login, Check your Username and Password";
redirect("login.php");
}
}
}
?>


<div class="login-alerts">
<?php if(! session_id()) {
session_start();
}
if(! empty($_SESSION['error_msg'])) {
echo "<div class='alert alert-danger'>";
echo $_SESSION['error_msg'];
echo "</div>";
$_SESSION['error_msg'] = "";
}
if(! empty($_SESSION['msg'])) {
echo "<div class='alert alert-success'>";
echo $_SESSION['msg'];
echo "</div>";
$_SESSION['msg'] = "";
}
?>
</div>
<div class="form">
<div class="form-header">
<h3 class="text-center">Welcome to <span style="color: #b30b0b">Z</span>Blog</h3>
</div>
<div class="form-body">
<form class="form" action="login.php" method="POST" >
<div class="form-group">
<span class=""></span>
<input type="text" name="username" class="form-control" placeholder="Username" required autocomplete="off" >
</div>
<div class="form-group">
<span class=""></span>
<input type="password" name="password" class="form-control" placeholder="Password" required autocomplete="off">
</div>
<div class="form-group">
<input style="float: right;" type="submit" name="admin_login" class="btn btn-default" value="Login" >
<a href="" style="float: left;">Forgot your password?</a>
</div>
</form>
</div>

</div>

<?php include "inc/footer.php"; ?>


function



function get_admin_login($username, $password) {
include "connect.php";
$sql = "SELECT id, username, password FROM admins WHERE username = ? && password = ? ";
try {
$result = $con->prepare($sql);
$result->bindValue(1,$username, PDO::PARAM_STR);
$result->bindValue(2,$password, PDO::PARAM_STR);

$result->execute();
return $result->fetchAll(PDO::FETCH_ASSOC);
}catch(Exception $e) {
echo "Error: ". $e->getMessage(). "n";
return false;
}


}



It always gives me this error ( Wrong Login, Check your Username and Password )
which means that $admin is empty. thanks










share|improve this question














I am trying to make login function which it takes two arguments username and password but when I check and use this function on login.php file if any value has returned from this function but it do not give me anything.



this is post request and all login file



 <?php 
include "inc/header.php";
include "inc/functions.php";

if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST["admin_login"])) {

$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);

$admin = get_admin_login($username, $password);

if(! session_id()){
session_start();
}
if(! empty($admin)) {
if($admin['username'] == $username) {
if($admin['password'] == $password) {
$_SESSION['msg'] = "Welcome Again " . $username;
redirect("index.php");
}else {
$_SESSION['error_msg'] = "Wrong Password";
redirect("login.php");
}
}else {
$_SESSION['error_msg'] = "Wrong Username";
redirect("login.php");
}
}else {
$_SESSION['error_msg'] = "Wrong Login, Check your Username and Password";
redirect("login.php");
}
}
}
?>


<div class="login-alerts">
<?php if(! session_id()) {
session_start();
}
if(! empty($_SESSION['error_msg'])) {
echo "<div class='alert alert-danger'>";
echo $_SESSION['error_msg'];
echo "</div>";
$_SESSION['error_msg'] = "";
}
if(! empty($_SESSION['msg'])) {
echo "<div class='alert alert-success'>";
echo $_SESSION['msg'];
echo "</div>";
$_SESSION['msg'] = "";
}
?>
</div>
<div class="form">
<div class="form-header">
<h3 class="text-center">Welcome to <span style="color: #b30b0b">Z</span>Blog</h3>
</div>
<div class="form-body">
<form class="form" action="login.php" method="POST" >
<div class="form-group">
<span class=""></span>
<input type="text" name="username" class="form-control" placeholder="Username" required autocomplete="off" >
</div>
<div class="form-group">
<span class=""></span>
<input type="password" name="password" class="form-control" placeholder="Password" required autocomplete="off">
</div>
<div class="form-group">
<input style="float: right;" type="submit" name="admin_login" class="btn btn-default" value="Login" >
<a href="" style="float: left;">Forgot your password?</a>
</div>
</form>
</div>

</div>

<?php include "inc/footer.php"; ?>


function



function get_admin_login($username, $password) {
include "connect.php";
$sql = "SELECT id, username, password FROM admins WHERE username = ? && password = ? ";
try {
$result = $con->prepare($sql);
$result->bindValue(1,$username, PDO::PARAM_STR);
$result->bindValue(2,$password, PDO::PARAM_STR);

$result->execute();
return $result->fetchAll(PDO::FETCH_ASSOC);
}catch(Exception $e) {
echo "Error: ". $e->getMessage(). "n";
return false;
}


}



It always gives me this error ( Wrong Login, Check your Username and Password )
which means that $admin is empty. thanks







php pdo






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 19 at 18:39









Ebrahem SamerEbrahem Samer

6




6













  • Did you check if you receive correctly the fields of username and password? Try echo ... these fields. Make a debugging.

    – Vasilis Greece
    Jan 19 at 18:45













  • Never store passwords in clear text! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Jan 19 at 18:58











  • Why do you sanitize password?

    – Dharman
    Jan 19 at 18:59











  • Vasilis Greece , when I echo username and password nothing appear in the page

    – Ebrahem Samer
    Jan 19 at 19:04











  • Does this return an array of results or just one row ? return $result->fetchAll(PDO::FETCH_ASSOC);

    – Matthew Page
    Jan 19 at 19:06



















  • Did you check if you receive correctly the fields of username and password? Try echo ... these fields. Make a debugging.

    – Vasilis Greece
    Jan 19 at 18:45













  • Never store passwords in clear text! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Jan 19 at 18:58











  • Why do you sanitize password?

    – Dharman
    Jan 19 at 18:59











  • Vasilis Greece , when I echo username and password nothing appear in the page

    – Ebrahem Samer
    Jan 19 at 19:04











  • Does this return an array of results or just one row ? return $result->fetchAll(PDO::FETCH_ASSOC);

    – Matthew Page
    Jan 19 at 19:06

















Did you check if you receive correctly the fields of username and password? Try echo ... these fields. Make a debugging.

– Vasilis Greece
Jan 19 at 18:45







Did you check if you receive correctly the fields of username and password? Try echo ... these fields. Make a debugging.

– Vasilis Greece
Jan 19 at 18:45















Never store passwords in clear text! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

– Dharman
Jan 19 at 18:58





Never store passwords in clear text! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

– Dharman
Jan 19 at 18:58













Why do you sanitize password?

– Dharman
Jan 19 at 18:59





Why do you sanitize password?

– Dharman
Jan 19 at 18:59













Vasilis Greece , when I echo username and password nothing appear in the page

– Ebrahem Samer
Jan 19 at 19:04





Vasilis Greece , when I echo username and password nothing appear in the page

– Ebrahem Samer
Jan 19 at 19:04













Does this return an array of results or just one row ? return $result->fetchAll(PDO::FETCH_ASSOC);

– Matthew Page
Jan 19 at 19:06





Does this return an array of results or just one row ? return $result->fetchAll(PDO::FETCH_ASSOC);

– Matthew Page
Jan 19 at 19:06












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54270215%2fi-want-to-retrieve-one-admin-to-login-depends-on-his-username-and-password-but-n%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54270215%2fi-want-to-retrieve-one-admin-to-login-depends-on-his-username-and-password-but-n%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre