not functioning in while($row->$statement->fetch()) using php PDO












0














if(isset($_POST['btnLogin']))
{
$username = $_POST['txtusername'];
$pass_word = $_POST['txtpassword'];
$hashed_password = crypt(sha1($pass_word));


$sqlQuery = "SELECT * from users WHERE username = :username AND password = :password" ;
$statement = $conn->prepare($sqlQuery);
$statement->execute(array(':username' =>$user , ':password'=>$hashed_password));

while($row->$statement->fetch())
{
$id = $row['id'];
$username = $row['username'];
$password = $row['password'];

if(strcmp('$password', '$hashed_password') == 0)
{
echo "<script type='text/javascript'>console.log("Sucess");</script>";
}
else
{
echo "<script type='text/javascript'>console.log("Failed");</script>";
}

}

}


In here I am implementing the Sign in a page using PHP PDO codes.
I have no previous experience in using PHP PDO.I do the Sign up page without any errors but unfortunately program is not execute after




while($row->$statement->fetch())




here are the HTML codes



<section>

<div class="container">
<div class="login-form">
<h1>Sign In</h1>
<form id="login-form" method="post" action="">
<div class="form-group">
<input type="text" name="txtusername" placeholder="Username" data-validation="required">
</div>
<div>
<input type="password" name="txtpassword" placeholder="Password" data-validation="required">
</div>
<input type="submit" name="btnLogin" value="Login">
</form>
</div>
</div>
</section>


PHP VERSION : 5.3.8



Please give any suggestion to me for solve it










share|improve this question




















  • 3




    That's because your while($row->$statement should be while($row=$statement.
    – Funk Forty Niner
    Nov 22 at 18:15








  • 1




    Voted this as a typographical error.
    – Funk Forty Niner
    Nov 22 at 18:23










  • @FunkFortyNiner i did change which is you mentioned above but it stil not working
    – Surath Gunawardena
    Nov 22 at 18:25






  • 1




    Enable error reporting and error handling on the query php.net/manual/en/pdo.error-handling.php - The password should have also been saved as the same hash, but I don't know why you are using what you're using now, why not use password_hash() and password_verify() instead? While making sure the password column is long enough to hold the hash.
    – Funk Forty Niner
    Nov 22 at 18:29






  • 1




    password_hash() has been available since PHP 5.5. If it's not available, that means you are wanting to handle sensitive user data with code that has been EOL for at least 5 years? Bad idea!
    – miken32
    Nov 22 at 19:58
















0














if(isset($_POST['btnLogin']))
{
$username = $_POST['txtusername'];
$pass_word = $_POST['txtpassword'];
$hashed_password = crypt(sha1($pass_word));


$sqlQuery = "SELECT * from users WHERE username = :username AND password = :password" ;
$statement = $conn->prepare($sqlQuery);
$statement->execute(array(':username' =>$user , ':password'=>$hashed_password));

while($row->$statement->fetch())
{
$id = $row['id'];
$username = $row['username'];
$password = $row['password'];

if(strcmp('$password', '$hashed_password') == 0)
{
echo "<script type='text/javascript'>console.log("Sucess");</script>";
}
else
{
echo "<script type='text/javascript'>console.log("Failed");</script>";
}

}

}


In here I am implementing the Sign in a page using PHP PDO codes.
I have no previous experience in using PHP PDO.I do the Sign up page without any errors but unfortunately program is not execute after




while($row->$statement->fetch())




here are the HTML codes



<section>

<div class="container">
<div class="login-form">
<h1>Sign In</h1>
<form id="login-form" method="post" action="">
<div class="form-group">
<input type="text" name="txtusername" placeholder="Username" data-validation="required">
</div>
<div>
<input type="password" name="txtpassword" placeholder="Password" data-validation="required">
</div>
<input type="submit" name="btnLogin" value="Login">
</form>
</div>
</div>
</section>


PHP VERSION : 5.3.8



Please give any suggestion to me for solve it










share|improve this question




















  • 3




    That's because your while($row->$statement should be while($row=$statement.
    – Funk Forty Niner
    Nov 22 at 18:15








  • 1




    Voted this as a typographical error.
    – Funk Forty Niner
    Nov 22 at 18:23










  • @FunkFortyNiner i did change which is you mentioned above but it stil not working
    – Surath Gunawardena
    Nov 22 at 18:25






  • 1




    Enable error reporting and error handling on the query php.net/manual/en/pdo.error-handling.php - The password should have also been saved as the same hash, but I don't know why you are using what you're using now, why not use password_hash() and password_verify() instead? While making sure the password column is long enough to hold the hash.
    – Funk Forty Niner
    Nov 22 at 18:29






  • 1




    password_hash() has been available since PHP 5.5. If it's not available, that means you are wanting to handle sensitive user data with code that has been EOL for at least 5 years? Bad idea!
    – miken32
    Nov 22 at 19:58














0












0








0







if(isset($_POST['btnLogin']))
{
$username = $_POST['txtusername'];
$pass_word = $_POST['txtpassword'];
$hashed_password = crypt(sha1($pass_word));


$sqlQuery = "SELECT * from users WHERE username = :username AND password = :password" ;
$statement = $conn->prepare($sqlQuery);
$statement->execute(array(':username' =>$user , ':password'=>$hashed_password));

while($row->$statement->fetch())
{
$id = $row['id'];
$username = $row['username'];
$password = $row['password'];

if(strcmp('$password', '$hashed_password') == 0)
{
echo "<script type='text/javascript'>console.log("Sucess");</script>";
}
else
{
echo "<script type='text/javascript'>console.log("Failed");</script>";
}

}

}


In here I am implementing the Sign in a page using PHP PDO codes.
I have no previous experience in using PHP PDO.I do the Sign up page without any errors but unfortunately program is not execute after




while($row->$statement->fetch())




here are the HTML codes



<section>

<div class="container">
<div class="login-form">
<h1>Sign In</h1>
<form id="login-form" method="post" action="">
<div class="form-group">
<input type="text" name="txtusername" placeholder="Username" data-validation="required">
</div>
<div>
<input type="password" name="txtpassword" placeholder="Password" data-validation="required">
</div>
<input type="submit" name="btnLogin" value="Login">
</form>
</div>
</div>
</section>


PHP VERSION : 5.3.8



Please give any suggestion to me for solve it










share|improve this question















if(isset($_POST['btnLogin']))
{
$username = $_POST['txtusername'];
$pass_word = $_POST['txtpassword'];
$hashed_password = crypt(sha1($pass_word));


$sqlQuery = "SELECT * from users WHERE username = :username AND password = :password" ;
$statement = $conn->prepare($sqlQuery);
$statement->execute(array(':username' =>$user , ':password'=>$hashed_password));

while($row->$statement->fetch())
{
$id = $row['id'];
$username = $row['username'];
$password = $row['password'];

if(strcmp('$password', '$hashed_password') == 0)
{
echo "<script type='text/javascript'>console.log("Sucess");</script>";
}
else
{
echo "<script type='text/javascript'>console.log("Failed");</script>";
}

}

}


In here I am implementing the Sign in a page using PHP PDO codes.
I have no previous experience in using PHP PDO.I do the Sign up page without any errors but unfortunately program is not execute after




while($row->$statement->fetch())




here are the HTML codes



<section>

<div class="container">
<div class="login-form">
<h1>Sign In</h1>
<form id="login-form" method="post" action="">
<div class="form-group">
<input type="text" name="txtusername" placeholder="Username" data-validation="required">
</div>
<div>
<input type="password" name="txtpassword" placeholder="Password" data-validation="required">
</div>
<input type="submit" name="btnLogin" value="Login">
</form>
</div>
</div>
</section>


PHP VERSION : 5.3.8



Please give any suggestion to me for solve it







php pdo while-loop fetch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 19:42









RiggsFolly

69.7k1864109




69.7k1864109










asked Nov 22 at 18:08









Surath Gunawardena

66




66








  • 3




    That's because your while($row->$statement should be while($row=$statement.
    – Funk Forty Niner
    Nov 22 at 18:15








  • 1




    Voted this as a typographical error.
    – Funk Forty Niner
    Nov 22 at 18:23










  • @FunkFortyNiner i did change which is you mentioned above but it stil not working
    – Surath Gunawardena
    Nov 22 at 18:25






  • 1




    Enable error reporting and error handling on the query php.net/manual/en/pdo.error-handling.php - The password should have also been saved as the same hash, but I don't know why you are using what you're using now, why not use password_hash() and password_verify() instead? While making sure the password column is long enough to hold the hash.
    – Funk Forty Niner
    Nov 22 at 18:29






  • 1




    password_hash() has been available since PHP 5.5. If it's not available, that means you are wanting to handle sensitive user data with code that has been EOL for at least 5 years? Bad idea!
    – miken32
    Nov 22 at 19:58














  • 3




    That's because your while($row->$statement should be while($row=$statement.
    – Funk Forty Niner
    Nov 22 at 18:15








  • 1




    Voted this as a typographical error.
    – Funk Forty Niner
    Nov 22 at 18:23










  • @FunkFortyNiner i did change which is you mentioned above but it stil not working
    – Surath Gunawardena
    Nov 22 at 18:25






  • 1




    Enable error reporting and error handling on the query php.net/manual/en/pdo.error-handling.php - The password should have also been saved as the same hash, but I don't know why you are using what you're using now, why not use password_hash() and password_verify() instead? While making sure the password column is long enough to hold the hash.
    – Funk Forty Niner
    Nov 22 at 18:29






  • 1




    password_hash() has been available since PHP 5.5. If it's not available, that means you are wanting to handle sensitive user data with code that has been EOL for at least 5 years? Bad idea!
    – miken32
    Nov 22 at 19:58








3




3




That's because your while($row->$statement should be while($row=$statement.
– Funk Forty Niner
Nov 22 at 18:15






That's because your while($row->$statement should be while($row=$statement.
– Funk Forty Niner
Nov 22 at 18:15






1




1




Voted this as a typographical error.
– Funk Forty Niner
Nov 22 at 18:23




Voted this as a typographical error.
– Funk Forty Niner
Nov 22 at 18:23












@FunkFortyNiner i did change which is you mentioned above but it stil not working
– Surath Gunawardena
Nov 22 at 18:25




@FunkFortyNiner i did change which is you mentioned above but it stil not working
– Surath Gunawardena
Nov 22 at 18:25




1




1




Enable error reporting and error handling on the query php.net/manual/en/pdo.error-handling.php - The password should have also been saved as the same hash, but I don't know why you are using what you're using now, why not use password_hash() and password_verify() instead? While making sure the password column is long enough to hold the hash.
– Funk Forty Niner
Nov 22 at 18:29




Enable error reporting and error handling on the query php.net/manual/en/pdo.error-handling.php - The password should have also been saved as the same hash, but I don't know why you are using what you're using now, why not use password_hash() and password_verify() instead? While making sure the password column is long enough to hold the hash.
– Funk Forty Niner
Nov 22 at 18:29




1




1




password_hash() has been available since PHP 5.5. If it's not available, that means you are wanting to handle sensitive user data with code that has been EOL for at least 5 years? Bad idea!
– miken32
Nov 22 at 19:58




password_hash() has been available since PHP 5.5. If it's not available, that means you are wanting to handle sensitive user data with code that has been EOL for at least 5 years? Bad idea!
– miken32
Nov 22 at 19:58












1 Answer
1






active

oldest

votes


















0














Try the below. If it doesn't work, wrap your query in this and turn error reporting on.



if(isset($_POST['btnLogin']))
{
$username = $_POST['txtusername'];
$pass_word = $_POST['txtpassword'];
$hashed_password = crypt(sha1($pass_word));


$sqlQuery = "SELECT * from users WHERE username = :username AND password = :password" ;
$statement = $conn->prepare($sqlQuery);
$statement->execute(array(':username' =>$user , ':password'=>$hashed_password));

while($row = $statement->fetch_object())
{
$id = $row->id;
$username = $row->username;
$password = $row->password;

if(strcmp('$password', '$hashed_password') == 0)
{
echo '<script type="text/javascript">console.log("Success");</script>';
}
else
{
echo '<script type="text/javascript">console.log("Failed");</script>';
}

}


}






share|improve this answer





















    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%2f53436273%2fnot-functioning-in-whilerow-statement-fetch-using-php-pdo%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Try the below. If it doesn't work, wrap your query in this and turn error reporting on.



    if(isset($_POST['btnLogin']))
    {
    $username = $_POST['txtusername'];
    $pass_word = $_POST['txtpassword'];
    $hashed_password = crypt(sha1($pass_word));


    $sqlQuery = "SELECT * from users WHERE username = :username AND password = :password" ;
    $statement = $conn->prepare($sqlQuery);
    $statement->execute(array(':username' =>$user , ':password'=>$hashed_password));

    while($row = $statement->fetch_object())
    {
    $id = $row->id;
    $username = $row->username;
    $password = $row->password;

    if(strcmp('$password', '$hashed_password') == 0)
    {
    echo '<script type="text/javascript">console.log("Success");</script>';
    }
    else
    {
    echo '<script type="text/javascript">console.log("Failed");</script>';
    }

    }


    }






    share|improve this answer


























      0














      Try the below. If it doesn't work, wrap your query in this and turn error reporting on.



      if(isset($_POST['btnLogin']))
      {
      $username = $_POST['txtusername'];
      $pass_word = $_POST['txtpassword'];
      $hashed_password = crypt(sha1($pass_word));


      $sqlQuery = "SELECT * from users WHERE username = :username AND password = :password" ;
      $statement = $conn->prepare($sqlQuery);
      $statement->execute(array(':username' =>$user , ':password'=>$hashed_password));

      while($row = $statement->fetch_object())
      {
      $id = $row->id;
      $username = $row->username;
      $password = $row->password;

      if(strcmp('$password', '$hashed_password') == 0)
      {
      echo '<script type="text/javascript">console.log("Success");</script>';
      }
      else
      {
      echo '<script type="text/javascript">console.log("Failed");</script>';
      }

      }


      }






      share|improve this answer
























        0












        0








        0






        Try the below. If it doesn't work, wrap your query in this and turn error reporting on.



        if(isset($_POST['btnLogin']))
        {
        $username = $_POST['txtusername'];
        $pass_word = $_POST['txtpassword'];
        $hashed_password = crypt(sha1($pass_word));


        $sqlQuery = "SELECT * from users WHERE username = :username AND password = :password" ;
        $statement = $conn->prepare($sqlQuery);
        $statement->execute(array(':username' =>$user , ':password'=>$hashed_password));

        while($row = $statement->fetch_object())
        {
        $id = $row->id;
        $username = $row->username;
        $password = $row->password;

        if(strcmp('$password', '$hashed_password') == 0)
        {
        echo '<script type="text/javascript">console.log("Success");</script>';
        }
        else
        {
        echo '<script type="text/javascript">console.log("Failed");</script>';
        }

        }


        }






        share|improve this answer












        Try the below. If it doesn't work, wrap your query in this and turn error reporting on.



        if(isset($_POST['btnLogin']))
        {
        $username = $_POST['txtusername'];
        $pass_word = $_POST['txtpassword'];
        $hashed_password = crypt(sha1($pass_word));


        $sqlQuery = "SELECT * from users WHERE username = :username AND password = :password" ;
        $statement = $conn->prepare($sqlQuery);
        $statement->execute(array(':username' =>$user , ':password'=>$hashed_password));

        while($row = $statement->fetch_object())
        {
        $id = $row->id;
        $username = $row->username;
        $password = $row->password;

        if(strcmp('$password', '$hashed_password') == 0)
        {
        echo '<script type="text/javascript">console.log("Success");</script>';
        }
        else
        {
        echo '<script type="text/javascript">console.log("Failed");</script>';
        }

        }


        }







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 at 14:33









        Niall Lonergan

        453417




        453417






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53436273%2fnot-functioning-in-whilerow-statement-fetch-using-php-pdo%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

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            Alexandru Averescu

            Trompette piccolo