所有这些代码都写在同一页面上
<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')";
}
if(isset($_POST['submit']) && !empty($_POST['submit']))
不会触发,每次刷新页面时,它都会将帐户的详细信息发送到我的数据库。我究竟做错了什么?
注意:仍在学习PHP和WordPress
答案 0 :(得分:4)
$_POST['submit']
将始终设置且不为空,其值已设置为注册。
您需要检查username
和password
是否应该为空。因此写
if(!empty($_POST['username']) && !empty($_POST['password'])){
// querycode here
}