我有下面的代码设置。用户只需输入他们的电子邮件地址,单击提交按钮,然后应该被带到下一页。问题是即使他们没有输入电子邮件,它仍然会将他们带到那个页面我知道这可能是一个愚蠢的错误,但我似乎无法发现它。
?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 £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');
}}}?>
编辑上面的编辑代码以显示完整的 index.php,包括下面建议的代码。
alpharegister.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>