首页 > 解决方案 > 如何让错误实际显示在我的 php 页面上?

问题描述

所以我决定在隔离期间我要练习一些编码,为 9 月份的 Web 开发课程做准备。所以我一直在尝试创建一个简单的注册页面。似乎其他一切都很好,但是当我测试错误是否有效时,它们实际上并没有出现。我似乎找不到任何问题。我有一个单独的 php 错误文件,然后是我的注册文件和服务器文件。

这是我的注册表单的代码

 <!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>

这是我的错误代码

<?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 ?>

标签: phphtml

解决方案


推荐阅读