I am trying to create a register page and I was wondering if there is a better way of doing this. So what I was think was instead of typing every field or is this a good way of doing this?
This is what I have currently.
This is the form
<form action="" method="POST">
<input type="text" name="username" placeholder="Username:" />
<input type="password" name="password" placeholder="Password:" />
<input type="password" name="password" placeholder="Confirm password:" />
<input type="text" name="email" placeholder="Email:" />
<input type="text" name="first_name" placeholder="First name:" />
<input type="text" name="last_name" placeholder="Last name:" />
<input type="submit" name="register" value="REGISTER" />
</form>
This is what I have for PHP side
function reg_validation() {
if ($_POST['register']) {
if (empty($_POST['username'])) {
echo 'Please enter a username';
}
if (empty($_POST['password'])) {
echo 'Please enter a password';
}
if (empty($_POST['confirm_password'])) {
echo 'Please confirm your password';
}
if (empty($_POST['email'])) {
echo 'Please enter an email address';
}
if (empty($_POST['first_name'])) {
echo 'Please enter your first name';
}
if (empty($_POST['last_name'])) {
echo 'Please enter your last name';
}
}
}