Jump to content

form validation workflow


jimfog

Recommended Posts

Till now, upon the user submitting a form, validation checks were performed, and if passed a registration function was called.In the latter function where a connection to a db was made, a check was taking place is the submitted username is the same with another in the db. The above scheme though, I think is wrong. Because when the form is submitted all the relevant errors must be submitted at the same time-with the above logic this does not happen. So, I think it is flawed.What do you think? probably a check if there is a similar username(which means connecting to the db) must be made before the registration function gets called. Here is the registration function:

function register_enduser($post)	   	    { global $errorclass;	    $name=mysql_real_escape_string($_POST['name']);    $lastname=mysql_real_escape_string($_POST['lastname']);    $email= mysql_real_escape_string($_POST['e-mail']);    $passwd= mysql_real_escape_string($_POST['password']);        $conn = db_connect();    $conn->set_charset("utf8");	    $result = $conn->query("select * from credentials where email='" . $email . "'");		 if (!$result) {			 throw new Exception('Αδυναμία εκτέλεσης εντολής');		    return false;		 }	   if($result->num_rows>0) {		   $errorclass['existentemail']='there is a similar e-mail registered already.';			 return  false;		   		  }else		 {$result = $conn->query("insert into credentials values							 (NULL,'" .  $email . "','" .  $passwd . "')") or die(mysqli_error($conn));	   }				 if (!$result) {			 throw new Exception(something went wrong.');			 return false;		 }	    else{$result = $conn->query("insert into end_users values							 ('".$conn->insert_id."','" .  $name. "','" .  $lastname. "')") or die(mysqli_error($conn));}		   			 return true;			   }

The above functions inserts data into 2 tables, as you can see, just focus on the e-mail check.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...