使用php和mysql创建注册和登录表单,并且错误无法在注册表单上复制[重复]

问题描述 投票:0回答:1

我用php和mysql创建了一个注册表单,一个登录表单,一个服务器,错误和索引。我收到错误'注意:未定义的变量:第1行的D:\ XAMPP \ htdocs \ errors.php中的错误'仅在注册表单中,而登录表单工作正常。我无法想象4天这个问题在互联网上找不到任何东西。我在使用Dreamweaver CC。

这是我的registration.php的代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Registration Form</title>
<link rel="stylesheet" type="text/css" href="forms.css">
</head>
<body>
<div class="header">
	<h2>Register</h2>
</div>

<form method="post" action="register.php">
	<?php include('errors.php'); ?>
	<div class="input-group">
		<label>Name:</label>
		<input type="text" name="name">
	</div>
	<div class="input-group">
		<label>Surname:</label>
		<input type="text" name="surname">
	</div>
	<div class="input-group">
		<label>Password:</label>
		<input type="text" name="password_1">
	</div>
	<div class="input-group">
		<label>Confirm Paswword:</label>
		<input type="text" name="password_2">
	</div>
	<div class="input-group">
		<label>Student ID:</label>
		<input type="text" name="studentid">
	</div>
	<div class="input-group">
		<label>Email:</label>
		<input type="text" name="email">
	</div>
    <div class="input-group">
		<label>Course:</label>
		<input type="text" name="course">
	</div>	
	<div class="input-group">
		<center><button type="submit" name="register" class="btn">Register</button></center>
	</div>
	<p>
  		Already a registered student? <a href="login.php">Sign in</a>
  	</p>
</form>
</body>
</html>

这是我的errors.php代码

<?php  if (count($errors) > 0) : ?>
  <div class="error">
  	<?php foreach ($errors as $error) : ?>
  	  <p><?php echo $error ?></p>
  	<?php endforeach ?>
  </div>
<?php  endif ?>

注意:一切都保存在PHP文件而不是html中。

感谢您提出任何建议和帮助。

php mysql forms phpmyadmin dreamweaver
1个回答
0
投票

请尝试以下代码:

添加额外的isset()条件以检查名为$errors的变量是否存在。

    <?php  if (isset($errors)) : ?>
      <?php  if (count($errors) > 0) : ?>
        <div class="error">
          <?php foreach ($errors as $error) : ?>
            <p><?php echo $error; ?></p> // added a ';'
          <?php endforeach; ?> // added a ';'
        </div>
      <?php  endif; ?> // added a ';'
    <?php  endif; ?> 
© www.soinside.com 2019 - 2024. All rights reserved.