我正在为网站制作一份注册表格,但是它不会等到我按下按钮时才开始。当我打开页面时,已经在说我没有填写所有字段。
我已经在if语句的下面放了一个echo东西,该if语句在单击按钮之前不应该出现,但是它开始在屏幕上显示。
if ($_POST['reg']) {
echo "Clicked";
if($em==$em) {
$u_check = mysqli_query($connection, "SELECT username FROM users WHERE username='$un'");
$check = mysqli_num_rows($u_check);
if($check == 0){
if($fn&&$ln&&$un&&$em&&$pswd&&$pswd2){
if($pswd == $pswd2){
if(strlen($un)>25||strlen($fn)>25||strlen($ln)>25){
echo "The maximum limit for username/first name/last name is 25 characters!";
}
else
{
if(strlen($pswd)>30||strlen($fn)<5){
echo "Your password must be between 5 and 30 characters long!";
}
else
{
$pswd = password_hash($pswd, PASSWORD_DEFAULT);
$pswd2 = password_hash($pswd2, PASSWORD_DEFAULT);
$query=mysql_query("INSERT INTO users VALUES('','$un','$fn','$ln','$em','$pswd','$d','0')");
die ("<h2>Welcome to Notebook!</h2>Log into your account to get started...");
}
}
}
else
{
echo "Your passwords don't match!";
}
}
else
{
echo "Please fill in all the fields";
}
}
else
{
echo "Username already taken...";
}
}
}
//if($reg){
// echo "Clicked";
//}
?>
<input type="submit" name="reg" value="Sign Up">
(请注意,这些只是我摘录的几段代码)
答案 0 :(得分:0)
像这样启动代码
if (isset($_POST['reg'])){