I'm trying to write some code that returns the user to a signup page if some of their inputs doesn't satisfy the required inputs. Rather than doing what it's expected to do, it continues onto the signup.inc.php page
signup.inc.php code:
<?php
if(isset($POST['signup-submit'])) {
require 'config.inc.php';
$firstName = $_POST['fname'];
$lastName = $_POST['lname'];
$username = $_POST['uid'];
$email = $_POST['mail'];
$companyID = $_POST['cid'];
$accountType = $_POST['acctType'];
$password = $_POST['pwd'];
$passwordRepeat = $_POST['pwdrepeat'];
if (empty($firstName) || empty($lastName) || empty($username) || empty($email) || empty($password) || empty($passwordRepeat)) {
header("Location: signup.php?error=emptyfields&fname=".$firstName."&lname=".$lastName."&uid=".$username."&mail=".$email);
exit();
}
}
signup.php code:
<?php
require 'header.php';
?>
<main>
<br><br>
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<header class="card-header">
<a href="login.php" class="float-right btn btn-outline-primary mt-1">Login</a>
<h4 class="card-title mt-2">Sign up</h4>
</header>
<article class="card-body">
<form action="includes/signup.inc.php" method="post">
<div class="form-row">
<div class="col form-group">
<label>First name </label>
<input type="text" class="form-control" name="fname" placeholder="First Name">
</div>
<div class="col form-group">
<label>Last name</label>
<input type="text" class="form-control" name="lname" placeholder="Last Name">
</div>
</div>
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" name="uid" placeholder="Username">
</div>
<div class="form-group">
<label>Email address</label>
<input type="email" class="form-control" name="mail" placeholder="example: johndoe@gmail.com">
<small class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Company</label>
<input type="text" name="cid" class="form-control" placeholder="Enter the Company ID given to you. Eg: WO1 or TTL1">
<small class="form-text text-muted">Ensure that the correct Company ID is inserted so you
can get connected to your specfic content calendar.</small>
</div>
<div class="form-group col-md-6">
<label>Account Type</label>
<select id="inputState" name="acctType" class="form-control">
<option selected="">Client</option>
<option>Community Manager</option>
<option>Admin</option>
</select>
</div>
</div>
<div class="form-group">
<label>Password</label>
<input class="form-control" type="password" name="pwd" placeholder="Password">
</div>
<div class="form-group">
<label>Repeat Password</label>
<input class="form-control" type="password" name="pwdrepeat" placeholder="Repeat password">
</div>
<div class="form-group">
<button type="submit" class="btn btn-secondary btn-block" name="signup-submit">Signup</button>
</div>
<small class="text-muted"> <center>
By clicking the 'Signup' button, you confirm that you accept your
<a href="terms.php">Terms of use and Privacy Policy.</a> </center> </small>
</form>
</article>
<div class="border-top card-body text-center">Have an account? <a href="login.php">Login</a></div>
</div>
</div>
</div>
</div>
</main>
<br><br>
<?php
require 'footer.php';
?>
Other than it returning to signup.php, I that the values inputted into the form to be returned so users won't have to type the entire form over again...
So the url should look something like:
localhost/ContentManagementSystem/signup.php?error=emptyfields&fname=example&lname=&mail=example
where "lname" is the empty field. What am I doing wrong here?