I was working with registration login system. When I click register, It shows no results.It just refreshes the page. Seems that isset
is not working.Could there be an alternate method to do it?
<?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.';
}
?>
You have a typo. This line -
if(!empty($username) && !empty($password) && !empty($password_again) &&
empty($firstname) &&!empty($surname)) {
should be
if(!empty($username) && !empty($password) && !empty($password_again) &&
!empty($firstname) &&!empty($surname)) {
^ // **missed this**
Also as per Sean's comment change name='surname'
in your html.
因为您使用的是$_POST['surname'];
所以将您的Surname
更改为surname
$_POST['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.';
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.