将表单插入数据库[关闭]

I'm trying to insert my form information into a database that is already created. So far I have:

    <form action="insert.php" method="post">
      Username:
      Password:
      Confirm Password:
      <input type="submit">
      if loops {
        send alert and return back to form page; }
    </form>

My question is: using this code, will the user information still be sent to the database file if the if loops are activated or will I need an exit statement after every if loop? (I do not want any information sent if the if loops are activated).

Thanks

You need inputs on your form:

 <form action="insert.php" method="post">
       Username: <input type="text" name="username">
       Password: <input type="password" name="password"> 
       Confirm Password: <input type="password" name="confirm">
       <input type="submit" name="submit">
     </form>

Then on insert.php

if (isset($_POST['submit'])){
  $Error = 0;
 if (!isset($_POST['username'])){
  $Error++;
 }
 if (!isset($_POST['password'])){
  $Error++;
 }
 if (!isset($_POST['confirm'])){
  $Error++;
 }

 if ($Error > 0){
  echo "Error in HTML Validation";
  exit; 
 }


// continue post verification here. 

}

You can also validate your form in client-side and it is faster and reduces server load:

 <form name="myForm" action="insert.php" method="post"  onsubmit="return validateForm()>
      Username:
      Password:
      Confirm Password:
      <input type="submit">
    </form>

And write a javascript for validating your form:

<script type="text/javaScript">
function validateForm()
{
  //Here will be your validation logic
  //if input doesn't meet your requirement then return false 
  var x=document.forms["myForm"]["email"].value;
  if(x is not an email address) 
  return false;
  }
}
</script>