Guys... I am new to web development.I need to learn form validation and verification to create a sign up form. I know basic PHP and MySQL to create a simple login and sign up systems but i don't know form validation and verification much so i want to learn it from the beginning.If you have a tutorial or example or something like that to learn form validation please post it here. Your post will help 100s of php beginners like me to start PHP development. Thank you very much
By form validation I'm taking it that you're referring to server-side PHP form processing...so here's some basic stuff. Login: Say you have a login form with user_name, user_pass, submit_button using method="post". if(isset($_POST['submit_button']) && isset($_POST['user_name']) && isset($_POST['user_pass'])){ // submit_button would be the name= of your submit button. $user_name = mysql_real_escape_string($_POST['user_name']); $user_pass = mysql_real_escape_string($_POST['user_pass']); // now query the database for the user_name $q = mysql_query("select * from user_table_name where user_name = '$user_name' limit 1"); if(mysql_num_rows()!=1){ // user_name doesn't exist }else{ // user_name exists so check if password matches $getinfo = mysql_fetch_assoc($q); $real_user_pass = $getinfo['user_pass']; if($user_pass == md5($real_user_pass)){ // log the user in }else{ // password is incorrect! } } } Code (markup): Sign Up: Say you have a signup form with user_name, user_pass, user_email, submit_signup, using method="post"... if(isset($_POST['submit_signup'])){ $user_name = mysql_real_escape_string($_POST['user_name']); $user_pass = mysql_real_escape_string($_POST['user_pass']); $user_email = mysql_real_escape_string($_POST['user_email']); // first make sure email address is properly formatted function validate_email($email) { return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)); } $test_email = validate_email($user_email); if(!$test_email){ // email address not proper format! }else{ // keep going... // make sure user_name is available (not in use already) by querying the db $chk = mysql_query("select user_name from user_table_name where user_name = '$user_name' limit 1"); if(mysql_num_rows()==1){ // user name already in the db }else{ // keep going // make sure password is long enough if(strlen($user_pass)>=5){ // 6 characters or greater // keep going // everything passed our tests so should be good to go... // now add to database $user_pass = md5($user_pass); // always encrypt vital user data! $insrt = mysql_query("insert into user_table_name values(NULL, '$user_name', '$user_pass', '$user_email');"); if(mysql_num_rows()==1){ // successfully added new account }else{ // database error echo mysql_error(); } }else{ // password not long enough } } } Code (markup): I learned most of what I know from browsing PHP.net although I've read quite a few PHP books, some of which went through real-world processes like these. I'll post back when I find some although quite busy at the moment. Hope this helps.
Since you know how to make a login, it can be assumed that you know how to do a post or a get. Validation implies veryfing if the data recived complies with something and based on that showing one thing or another. One more thing you might like to know in this area is how to do a redirect in php: header("Location: page"); Replace page with the URL to redirect to and make sure you have no echo in your script before that. I don't see why you would need a tutorial for that since you know the basics.