I have recently encountered dis error while doing <b>page validation</b> for my site.
I have been trying a lot ,but still could not find the solution.
Being a newbie to PHP, I would be obliged if u guys could help me out.
The URL of d site is,
http://www.dmcewriteups.co.cc/register.php
I do not understand,how all[except 1] errors vanish when I press reset button of the form
The HTML n PHP code is as follows :
<html>
<head>
<link href="style_register.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#474747">
<div id="form-container">
<center>
<h2>Registration form</h2>
</center>
<fieldset>
<form action = "register.php" method="POST">
<div class="error">
<?php
if($_POST['submit'])
{
$username = $_POST['username'];
$password = $_POST['password'];
$name = $_POST['firstname'];
$surname = $_POST['lastname'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$divroll = $_POST['divroll'];
$key = $_POST['key'];
$errorstring = "";
function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
if(!$username)
$errorstring = $errorstring."Username<br>";
if(!$password)
$errorstring = $errorstring."Password<br>";
if(!$name)
$errorstring = $errorstring."Name<br>";
if(!$surname)
$errorstring = $errorstring."Surname<br>";
if(!$email)
$errorstring = $errorstring."Email<br>";
if(!mobile)
$errorstring = $errorstring."Mobile<br>";
if(!$divroll)
$errorstring = $errorstring."Dive/Roll<br>";
if(!$key)
$errorstring = $errorstring."Key<br>";
if($errorstring!="")
echo "<h4>Please fill out the following fields:</h4>$errorstring";
else
{
if($mobile.length<10 && ctype_digit($mobile))
echo "Enter a valid mobile no.<BR>";
if($username.length<4)
echo "Enter a valid username<BR>";
if($name.length <3)
echo "Enter a valid First Name<BR>";
if($surname.length <3)
echo "Enter a valid Last Name<BR>";
if($password.length <5 && ctype_alnum($password))
echo "Enter a valid alphanumeric password<BR>";
if($divroll.length>4 && ctype_alnum($divroll))
echo "Enter a valid password<BR>";
if (!valid_email($email))
echo "Enter a valid email<BR>";
if($key=="qazxsw123")
{
$connect=mysql_connect("mysql6.000webhost.com","XYZ","ABC");
mysql_select_db("a3537046_info",$connect) or die (mysql_errno().":<b> ".mysql_error()."</b>");
mysql_query("INSERT INTO users (username,password,name,surname,email,divroll,mobile)
VALUES('$username','$password','$name','$surname','$email','$divroll','$mobile')")or die(mysql_error());
header("location:signin.html");
}
else
echo "Enter a valid key<BR>";
}
}
if($_POST['reset'])
{
$username = $_POST['username'];
$password = $_POST['password'];
$name = $_POST['firstname'];
$surname = $_POST['lastname'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$divroll = $_POST['divroll'];
$key = $_POST['key'];
$username = "";
$password = "";
$name = "";
$surname = "";
$email = "";
$mobile = "";
$divroll = "";
$key = "";
}
?>
</div>
<div class="field">
<label for="username">Username :</label>
<input type='text' name='username' value = '<?php echo $username ?>'>
<div class ="example">example: john</div>
</div>
<div class="field">
<label for="password">Password :</label>
<input type='password' name='password' value = '<?php echo $password ?>'>
<div class ="example">example: john123</div>
</div>
<div class="field">
<label for="Name">First Name :</label>
<input name='firstname' type="text" value = '<?php echo $name ?>'>
</div>
<div class="field">
<label for="Surname">Last Name :</label>
<input type='text' name='lastname' value = '<?php echo $surname ?>'>
</div>
<div class ="field">
<label for="emailid">Email Id :</label>
<input type='text' name='email' value = '<?php echo $email ?>'>
<div class ="example">example: username@domain.com</div>
</div>
<div class ="field">
<label for="mobile">Mobile No. :</label>
<input type='text' name='mobile' value = '<?php echo $mobile ?>'>
<div class ="example">example: 99XXXXXX09</div>
</div>
<div class ="field">
<label for="divroll">Div/Roll No. :</label>
<input type='text' name='divroll' value = '<?php echo $divroll ?>'>
<div class ="example">example: A11</div>
</div>
<div class="field">
<label for="key">Secret Key:</label>
<input type='text' name='key' value = '<?php echo $key ?>'>
<div class ="example">Ask admins !!!</div>
</div>
<div class="field">
<input class="submit-button" name = "submit" value="Submit" type="submit">
<input class="reset-button" name = "reset" value="Reset" type="submit">
</div>
</form>
</fieldset>
</div>
</body>
</html>