I'm sure this get's asked a lot but everybody's code is different, but I'm having trouble validating my registration form.
I'll post my code below the snippet.
Now what exactly am I doing wrong? I want to make sure every field is filled out but even if I use the code below or I add in a die() function with an error echo the rest of the code still gets executed and the form is sent off.
The snippet below is the sort of thing I've been trying.
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'];
This is my current code as it stands.
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.";
}
}