【发布时间】:2019-08-01 21:01:28
【问题描述】:
我正在尝试编写一些代码,如果用户的某些输入不满足所需的输入,则将其返回到注册页面。它没有做预期做的事情,而是继续进入 signup.inc.php 页面
signup.inc.php 代码:
<?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 代码:
<?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';
?>
除了返回signup.php之外,我将输入到表单中的值返回,这样用户就不必再次输入整个表单...
所以网址应该类似于:
localhost/ContentManagementSystem/signup.php?error=emptyfields&fname=example&lname=&mail=example
其中“lname”是空字段。我在这里做错了什么?
【问题讨论】:
-
第一个代码块是“signup.inc.php”文件吗?此外,conventionally、
.inc是文件类型,而不是.inc.php。 -
@zbee 是的,第一块代码是 signup.inc.php 文件
-
你试过直接导航到
signup.inc.php吗?那应该重定向你 -
@zbee 导航到它时,它返回一个空白页
-
所以即使那样它也无法重定向;确保errors are being displayed 和/或
var_dump您的每个条件句(例如:var_dump(empty($username), ...)检查他们是否正在评估您对它们的期望(您希望它们在您直接加载页面时都返回true) )。
标签: php