0

So I've decided that while stuck in quarantine I am going to practice some coding in preparation for my web development class in September. So I have been trying to create a simple registration page. It seems as though everything else works just fine but when I test to see if the errors work they don't actually show up. I can't seem to find anything wrong with it. I have a seperate php file for errors and then my registration file and a server file.

This is the code for my registration form

 <!doctype html>
<html>
<body>
   <div class=container>
<h1>Register</h1>
<p>Please fill in the form to create an account</p>
<form method="post" action="register.php">
  <?php include ('errors.php'); ?> 
    <label>Email: </label>
    <input type="text" name="email" value="<?php echo $username; ?>"><br>
    <label>Username: </label>
    <input type="text" name="username" value="<?php echo $email; ?>"><br>
    <label>Password: </label>
    <input type="Password" name="password"><br>
    <label>Confirm Password: </label>
    <input type="password" name="password2"><br>
    <button class="registerbtn" type="submit" name="registerbtn">Register</button>
</form>

<p align="center">Already have an account? <a href="login.php">Sign in</a>.</p>
</div>

<?php
include 'footer.php'
?>
</body>
</html>

This is the code for my errors

<?php
$errors = array();
?>

<?php  if (count($errors) > 0) : ?>
  <div class="error">
    <?php foreach ($errors as $error) : ?>
      <p><?php echo $error ?></p>
    <?php endforeach ?>
  </div>
<?php  endif ?>
Dianne
  • 1
  • 2
  • 2
    At the moment, it's doing exactly what it needs to do. You set `$errors` to an empty array, then the next section you have it counting the errors. But you have not added the code to actually fill in the errors array. – aynber May 11 '20 at 16:40
  • Agreed, you are not actually generating any errors which could be displayed. Is there somewhere else you were trying to generate them from? – ADyson May 11 '20 at 17:16
  • oh shoot yeah sorry thats in my server php file forgot to post that – Dianne May 11 '20 at 18:57
  • well you can press the "edit" button under your question and add it, so we can see it :-) – ADyson May 11 '20 at 23:04

0 Answers0