代码在PHP中不起作用.什么';It’他错了


Code not working in PHP. What's wrong?

我使用的是注册登录系统。当我点击注册时,它没有显示任何结果。它只是刷新页面。似乎isset不工作。能有其他方法吗?

 <?php
 require 'core.inc.php';
 require 'connect.inc.php';
 if(!loggedin())  {
 $check_array =        
 array('username','password','password_again','firstname','surname'); 
 if(!array_diff($check_array,array_keys($_POST)))  {
 $username = $_POST['username'];
  $password = $_POST['password'];
  $password_again = $_POST['password_again'];
  $firstname = $_POST['firstname'];
  $surname = $_POST['surname'];
if(!empty($username) && !empty($password) && !empty($password_again) &&                    
 empty($firstname) &&!empty($surname)) {
      echo 'Ok.';
}
     else  {
           echo 'All fields are required.';
}
}
     else echo 'no.';
?>

<form action="register.php" method="POST">
Username:<br><input type ="text" name="username"><br>
Password:<br><input type ="password" name= "password"><br>
Password again:<br><input type="password" name="password_again"><br>
Firstname:<br><input type="text" name="firstname"><br>
Surname:<br><input type="text"  name="Surname"><br><br>
<input type="submit" value= "Register"><br>
</form>


<?php
}
else if(loggedin())  {
echo 'You''re already registered.';
}
?>

您有一个打字错误。这条线-

if(!empty($username) && !empty($password) && !empty($password_again) &&                    
 empty($firstname) &&!empty($surname)) {

应该是

if(!empty($username) && !empty($password) && !empty($password_again) &&                    
 !empty($firstname) &&!empty($surname)) {
 ^ // **missed this**

同样根据肖恩的评论,在你的html中更改name='surname'

由于使用$_POST['surname']; ,请将Surname更改为surname

Surname:<br><input type="text"  name="surname"><br><br>
    <?php
     require 'core.inc.php';
     require 'connect.inc.php';
     if(!loggedin())  {
     $check_array =        
     array('username','password','password_again','firstname','surname'); 
     if(!array_diff($check_array,array_keys($_POST)))  {
     $username = $_POST['username'];
      $password = $_POST['password'];
      $password_again = $_POST['password_again'];
      $firstname = $_POST['firstname'];
      $surname = $_POST['surname'];
    if(!empty($username) && !empty($password) && !empty($password_again) &&                    
     !empty($firstname) && !empty($surname)) {
          echo 'Ok.';
    }
         else  {
               echo 'All fields are required.';
    }
    }
         else echo 'no.';
    ?>

    <form action="register.php" method="POST">
    Username:<br><input type ="text" name="username"><br>
    Password:<br><input type ="password" name= "password"><br>
    Password again:<br><input type="password" name="password_again"><br>
    Firstname:<br><input type="text" name="firstname"><br>
    Surname:<br><input type="text"  name="surname"><br><br>
    <input type="submit" value= "Register"><br>
    </form>


    <?php
    }
    else if(loggedin())  {
    echo 'You''re already registered.';
    }
    ?>