title: Why is my form being wrongly validated?
body: <p>I'm sure this get's asked a lot but everybody's code is different, but I'm having trouble validating my registration form.</p>
  
  <p>I'll post my code below the snippet.</p>
  
  <p>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.</p>
  
  <p>The snippet below is the sort of thing I've been trying.</p>
  
  <pre><code>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'];
  </code></pre>
  
  <p>This is my current code as it stands.</p>
  
  <pre><code>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.";
  }
  }
  </code></pre>