Hi everyone, here in this code i have inserted javascript form validation and it is working as well, but when i click the submit button for empty fileds it mentions that the filed is empty but at the same time it adds the empty record.. i have checked my code but could not find any error please check it once. any kind of help will be appreciated. thanx :)
<?php include("../includes/pre-header.php");?>
<script type="text/javascript" src="../javascript/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="../javascript/jQuery.validity.min.js"></script>
<script type="text/javascript">
$(function() {
$("form").validity(function() {
$("#email")
.require()
.match("email", "Please Type a Valid E-mail address!!")
$("#password")
.require()
.minLength(5, "Your Password must be 5 characters long!!");
$("#firstname")
.require("This Field Must Be Filled!!")
.minlength(6, "Your Name must be 6 characters long!!")
.maxlength(20, "Your Name must be less than 20 characters!!")
$("#lastname")
.require("This Filed Must Be Filled!!")
.minlength(6, "Your Name must be 6 characters long!!")
.maxlength(20, "Your Name must be less than 20 characters!!")
});
});
</script>
<title>Manage Users</title>
</head>
//here i am inserting just the validation part and form part of the page bcoz code is lenghty
<form method="post" id="form" action="manage-users-action.php">
<label for="email">Email/Username:</label><input id="email" type="text" name="email" value="" class="text" /><br /><br />
<label for="password">Password:</label><input id="password" type="password" name="password" value="" class="text" /><br /><br />
<label for="firstname">First Name:</label><input id="firstname" type="text" name="firstname" value="" class="text" /><br /><br />
<label for="lastname">Last Name:</label><input id="lastname" type="text" name="lastname" value="" class="text" /><br /><br />
<label for="intro">Brief Introduction:</label><br /><textarea name="intro"> </textarea><br /><br />
<label for="qualification">Qualification</label><br /><textarea name="qualification"></textarea><br /><br />
<label for="image">Profile Image</label><input type="file" name="image" value="" /><br /><br />
<label>Type:</label><br />
<input type="radio" name="type" value="S" checked />Student <br /> <br />
<input type="radio" name="type" value="T" />Teacher<br /><br />
<input type="submit" name="submit" value="Submit" class="button" />
</form>
this is manage-users-action.php
<?php include("../includes/config.php");?>
<?php
$fname=$_POST['firstname'];
$lname=$_POST['lastname'];
$type=$_POST['type'];
$email=$_POST['email'];
$pwd=$_POST['password'];
$image=$_FILES['image'];
$intro=$_POST['intro'];
$qualification=$_POST['qualification'];
$recoverykey=md5(time());
$encpwd=md5($pwd);
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$check= mysql_query("SELECT email FROM accounts WHERE (email='".$email."')");
$result = mysql_num_rows($check);
if($result !== 0)
{
echo header("Location:manage-users.php?status=3");
}
else
{
$sql=("INSERT INTO accounts VALUES (NULL,'".$email."','".$encpwd."','".$fname."','".$lname."','".$type."','".$recoverykey."','".$image."','".$intro."','".$qualification."')");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo header("Location:manage-users.php?status=1");
}
exit();
mysql_close($con);
?>