Jump to content

validation


phppoet

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.