phppoet Posted August 5, 2011 Share Posted August 5, 2011 i am trying to validate a simple registration form using below code...but i am confused about the looping in it...or anyone can suggest me abetter way to validate it <html> <head> </head> <body> <div style="width:400px; height:500px; margin: 0 auto;"> <form name="register" action="register_action.php" method="post"> <fieldset> <legend>Personal information:</legend> <input type="text" name="username"> <input type="password" name="password"> <input type="submit" value="register"> </fieldset> </form> </div> </body> </html> <?php if(isset($_GET['reg'])) { if($_GET['reg']==1) { $mess_l="try another username bro.."; } if($_GET['login']==2) { $mess_l="enter your username"; } echo "$mess_l"; } ?> <?php $username =$_POST['username']; $password =$_POST['password']; if (empty($username)) { header("location:register.php?reg=2"); elseif (empty ($password)) { header("location:login.php?login=3"); } elseif($username&&$password){ mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("jaf_login") or die(mysql_error()); $result = mysql_query("SELECT username FROM users WHERE username = '$username'") or die(mysql_error()); if(mysql_num_rows($result) == 0) {$query = "INSERT INTO users(username, password) VALUES('$username', '$password')"; mysql_query($query); header("location:login.php"); } else { header("location:register.php?reg=1"); } } ?> Link to comment https://forums.phpfreaks.com/topic/243914-validation/ Share on other sites More sharing options...
voip03 Posted August 5, 2011 Share Posted August 5, 2011 It 's look ok. just google it , Link to comment https://forums.phpfreaks.com/topic/243914-validation/#findComment-1252459 Share on other sites More sharing options...
phppoet Posted August 5, 2011 Author Share Posted August 5, 2011 can you give a better way to validate my form? Link to comment https://forums.phpfreaks.com/topic/243914-validation/#findComment-1252462 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.