Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP WordPress issue with isset() Function

All this code is written on the same page

 <form method="post" action = "http://mypage.lhosting.info/login/" >
    <p> Username: <input type="text" name = "username" /> </p><br>
    <p> Password: <input type="text" name = "password" /></p> <br>
    <input type="submit" name="submit" value="Register" />
 </form>

 if(isset($_POST['submit']) && !empty($_POST['submit'])) 
 {
   $username = mysqli_real_escape_string($conn, $_POST['username']);
   $password = mysqli_real_escape_string($conn, $_POST['password']);
   $sql = "INSERT INTO Duomenys (Username, Password) VALUES ('$username','$password')"; 
 }

The if(isset($_POST['submit']) && !empty($_POST['submit'])) does not trigger, it sends the account's details to my database everytime I refresh the page. What am I doing wrong?

Note: Still learning PHP and WordPress

like image 394
TheEnthusiast Avatar asked Apr 25 '26 10:04

TheEnthusiast


1 Answers

$_POST['submit'] will always set and not empty it's value is already set as Register.

You need to check that username and password should not empty. Hence write

if(!empty($_POST['username']) && !empty($_POST['password'])){
    // querycode here
}
like image 197
Ravi Avatar answered Apr 26 '26 23:04

Ravi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!