3

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

Frits
  • 7,341
  • 10
  • 42
  • 60
TheEnthusiast
  • 77
  • 1
  • 8

1 Answers1

4

$_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
}
Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42