0

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?

jarelly
  • 53
  • 6
  • Is the first block of code the "signup.inc.php" file? Additionally, [conventionally](https://stackoverflow.com/a/7129861/1843510), `.inc` is the file type, not `.inc.php`. – zbee Aug 01 '19 at 21:05
  • @zbee yes the first block of code is the signup.inc.php file – jarelly Aug 01 '19 at 21:14
  • Have you tried navigating directly to `signup.inc.php`? That should redirect you – zbee Aug 01 '19 at 21:17
  • @zbee when navigating to it, it returns a blank page – jarelly Aug 01 '19 at 21:22
  • So it is failing to redirect even then; make sure [errors are being displayed](https://stackoverflow.com/a/5438125/1843510), and/or `var_dump` each of your conditionals (like so: `var_dump(empty($username), ...)` to check if they are evaluating how you would expect them to be (you expect them to all return true when you load the page directly). – zbee Aug 01 '19 at 21:26
  • You have a typo in your condition: `if(isset($POST['signup-submit'])) {` change to: `if(isset($_POST['signup-submit'])) {` i.e. you forgot an underscore (`$POST` to `$_POST`) – jibsteroos Aug 01 '19 at 21:46
  • Thank you @jibsteroos. That was the error.. silly me :) – jarelly Aug 01 '19 at 22:01
  • No worries, happens to the best! – jibsteroos Aug 01 '19 at 22:03

1 Answers1

0

As pointed out by Jibsteroos, the error was the missing underscore this line:

if(isset($POST['signup-submit'])

It should be:

if(isset($_POST['signup-submit']))

jarelly
  • 53
  • 6