我确定这个问题得到了很多,但每个人的代码都不一样,但我在验证我的注册表时遇到了问题。
我会在代码段下面发布我的代码。
现在到底我做错了什么?我想确保每个字段都填写完毕,但即使我使用下面的代码,或者我添加了一个带有错误回显的die()函数,其余的代码仍然会被执行并且表单被发送出去。
下面的代码段就是我一直在尝试的事情。
if(isset($_POST["submit"])){
if(empty($firstname) || empty($lastname) || empty($username) || empty($password) ||
empty($passwordconf)
{
echo "You did not fill out the required fields.";
die();
}
$user=$_POST['user'];
$pass=$_POST['pass'];
这是我目前的代码。
if(isset($_POST["submit"])){
$user=$_POST['user'];
$pass=$_POST['pass'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$username = "DBname";
$password = "DBpass";
$hostname = "DBhost";
$md5pass = md5($pass);
if(empty($email)){ //this is what I've tried
$errors[] = "email cannot be left empty";
}
//connection to the database
$dbhandle = mysqli_connect($hostname, $username, $password)
or die("Unable to connect to server");
$con=mysql_connect($hostname, $username, $password) or die(mysql_error());
$select=mysql_select_db("Database", $con) or die("cannot select DB");
$query=mysql_query("SELECT * FROM login WHERE username='".$user."'");
$numrows=mysql_num_rows($query);
if($numrows==0)
{
$sql="INSERT INTO login(username,password,firstname,lastname,email)
VALUES('$user','$md5pass','$fname','$lname','$email')";
$result=mysql_query($sql);
if($result){
echo "Account Successfully Created, Please login to continue";
} else {
echo "Failure!";
}
} else {
echo "That username already exists! Please try again with another.";
}
}
答案 0 :(得分:0)
也许它在复制期间丢失了,但第二个如果需要关闭)
if(isset($_POST["submit"])){
if(empty($firstname) || empty($lastname) || empty($username) || empty($password) || empty($passwordconf)) {