0

I am trying to make a verification for my $_POST to database on PHP. I noticed something very strange. Whenever i use if(isset($_POST['login_btn'])), it gets authenticated, but when i use if(!empty($_POST['login_btn'])), notice that it never gets authenticated (NO WARNING as normal on !empty()...) But why is it not working on the same code? Isn't it both same and intercgangeable?

Here is my code i tried to get it to work.......Is there a difference in its application and working that i don't know?

if(!empty($_POST['submit'])){ $username = $_POST["username"]; $password = $_POST["password"]; include 'dbconnect.php'; $conn = "select * from USERS where password='$password' AND (username='$username')"; $result = mysqli_query($db, $conn); $projects = array(); if(mysqli_num_rows($result) == 1) { $projects || $logged_in_user = mysqli_fetch_assoc($result); ...........// other codes 
5
  • 1
    So var_dump($_POST['your_button']) and see it's value. Commented Jun 22, 2022 at 10:49
  • 1
    Warning: You are wide open to SQL Injections and should use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input! Even when your queries are executed only by trusted users, you are still in risk of corrupting your data. Escaping is not enough! Commented Jun 22, 2022 at 10:53
  • 1
    Never store passwords in clear text or using MD5/SHA1! Only store password hashes created using PHP's password_hash(), which you can then verify using password_verify(). Take a look at this post: How to use password_hash and learn more about bcrypt & password hashing in PHP Commented Jun 22, 2022 at 10:53
  • Yes, i understand the warning. I just simply put that out there for illustration of my problem. Just a simple illustration of it. Commented Jun 22, 2022 at 11:02
  • @u_mulder , I got a string(0) "" Commented Jun 22, 2022 at 11:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.