发送到标题位置,即使以前的表单不正确


Sending to header location even though previous form incorrect

我有下面的代码设置。用户只需输入他们的电子邮件地址,单击提交按钮,然后应转到下一页。问题是,即使他们没有输入电子邮件,它仍然会将他们带到该页面,我知道这可能是一个愚蠢的错误,但我似乎无法发现它。

?php
include('header.php');
include('side.php'); ?>
<div id="content">
<?php
if($_SESSION['uid'] != 1)
echo '
<h2>Alpha Registration</h2>
<p align="center">Registration for an Alpha Account costs &#163;5.<br>You will be asked to confirm and pay on the following page.</p>
<form method="post" action="alpharegister.php">
<div id="loginform"><center><table>
<tr><td>Email:</td><td><input type="text" class="box" name="email"></td></tr>
<tr><td colspan="2"><center><input type="submit" class="submit" name="registersubmit" value="Begin Registration"></center></td></tr>
</table></center></div></form>';
else {
}
if($_POST['registersubmit'] && (isset($_POST['email'] && isempty($_POST['email'])){
$email = protect($_POST['email']);
if(!$email) {
echo '<div class="incorrectlogin">You must enter a valid email address.</div>';
}else{
$checkemail = "/^[a-z0-9]+([_''.-][a-z0-9]+)*@([a-z0-9]+(['.-][a-z0-9]+)*)+''.[a-z]{2,}$/i";
if(!preg_match($checkemail, $email)) {
echo '<div class="incorrectlogin">You must enter a valid email address.</div>';
}else{
setcookie("AlphaEmail", $email, time()+3600);
header('Location: alpharegister.php');
}}}?>

编辑编辑了上面的代码以显示完整索引.php包括下面建议的代码。

阿尔法寄存器.php

<?php
include('header.php');
include('side.php');
?>
<div id="content">
<h1>Alpha Account Registration</h1>
<?php
echo 'Your email is ' .$_COOKIE["AlphaEmail"]. '!';
?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="FJP9C8CSJ73GG">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
</div>

添加了这个附加条件语句,以检查电子邮件输入值是否输入

if($_POST['registersubmit'] && (isset($_POST['email']) && !isempty($_POST['email']) )) {
// do you stuff here
}