<分区>
(这是我第一次尝试使用 php)
我有一个非常基本的注册页面。 http://graves-incorporated.com/test_sites/member_test/register/register.php
* 我只记得 PHP 代码没有出现在源代码中,所以这里是:
enter code here
<?php
include('connection.php');
if(isset($_POST['form'])){
if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['conf_pass']) || empty($_POST['email'])){
echo '<b>Please fill out all fields.</b>';
}elseif($_POST['password'] != $_POST['conf_pass']){
echo '<b>Your Passwords do not match.</b>';
}else{
$url = 'http://graves-incorporated.com/test_sites/plantation_park_2012/';
echo '<META HTTP-EQUIV=Refresh CONTENT="2; URL='.$url.'">';
echo '<b>Congrats, You are now Registered.</b>';
mysql_query("INSERT INTO users VALUES(NULL, '$_POST[username]', '$_POST[password]', '$_POST[email]')");
}
}
?>
我想确保我不会在数据库中获得重复的用户和/或电子邮件地址。我在 MySQL 中为用户名和电子邮件设置了一个唯一键,这阻止了它,但实际表单上的用户不知道,它仍然告诉他们“恭喜,你已注册”或任何它说的......哈哈
那么我可以在 php 代码中添加什么(以及代码中的什么地方)来防止这种情况发生?
感谢您帮助这位大菜鸟, 丹格雷夫斯