Hi to all
i have done validation on my HTML page but the problem is that when i press the submit button it show the alert message that name field is not specified but when i OK that message then data enter into the data base without specifying the name field.i want that i specify the name field then again press the submit button then data enter into database
html code
<html>
<head>
<script type="text/javascript" src="jstest.js"></script>
</head>
<img src="idtech_logo.jpg" alt="logo" width="1500" height="80" />
<body bgcolor="#1E90FF">
<form method="POST"
onsubmit="return validate_form(this)" action="insert.php">
<h1>
<font size="15" face="Monotype Corsiva" color="black">
<center>ID Technologies</center></font></h1>
<center>
<table>
<tr>
<td width="50%"> First Name: </td>
<td> <input type="text" name="fname" /> </td>
</tr>
<tr>
<td width="50%"> Last Name :</td>
<td> <input type="text" name="lname" /></td>
</tr>
<tr>
<td width="50%"> Organization Name:</td>
<td> <input type="text" name="oname"/></td>
</tr>
<tr>
<td width="50%">Email:</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td width="50%">Contact Number:</td>
<td><input type="text" name="cno" /></td>
</tr>
<tr>
<td width="50%">Duration in years:</td>
<td><input type="text" name="years"/ ></td>
</tr>
</table>
</center>
<br/>
<center>
<table>
<input type="radio"/>Extend<br/>
<input type="radio"/>Read Only<br/><br/>
<a href="WindowsFormsApplication6.exe">Download link</a>
</br></br>
<tr>
<td width="50%">MAC ID:</td>
<td><input type="text" name="mid" /></td>
</tr>
<tr>
<td width="50%">CPU ID:</td>
<td><input type="text" name="cid" /></td>
</tr>
<tr>
<td width="50%">MotherBoard ID:</td>
<td><input type="text" name="mbid" /></td>
</tr>
</table>
</center>
</br></br>
<center>
<input type="submit" value="submit"/>
</center>
</form>
</body>
</html>
jstest.js code
function validate_required(field,alerttxt) {
with (field) {
if (value==null||value=="") {
alert(alerttxt);
return false;
}
else {
return true;
}
}
}
function validate_email(field,alerttxt) {
with (field) {
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) {
alert(alerttxt);
return false;
} else {
return true;
}
}
}
function validate_form(thisform) {
with (thisform) {
if (validate_required(fname,"Please specify your First Name!")==false) {
name.focus();
return false;
}
if (validate_required(email,"Email must be filled out!")==false) {
email.focus();
return false;
}
if (validate_email(email,"Not a valid e-mail address!")==false) {
email.focus();
return false;
}
if (validate_required(oname,"Specify the organization name!")==false) {
color.focus();
return false;
}
if (validate_required(cno,"Enter your contact number!")==false) {
color.focus();
return false;
}
}
}
insert.php code
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("request_license", $con);
echo "connection establish </br></br>";
$sql="INSERT INTO user_data (Record_ID,First_Name, Last_Name, Name_Of_Organization,Email,Contact_number,Duration_In_Years,MAC_Address,CPU_ID,Motherboard_ID)
VALUES
('null','$_POST[fname]','$_POST[lname]','$_POST[oname]','$_POST[email]','$_POST[cno]','$_POST[years]','$_POST[mid]','$_POST[cid]','$_POST[mbid]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else{
echo "record added";
}
mysql_close($con)
?>
plz help me....