I am creating a page in which I am fetching data from table and showing data in textbox to allow user to update record. I also validate the user input to textbox. But the problem is when the user does not change any field and click on submit, it validates username field i.e. it always wants to change (or edit textbox) the value of textboxes.
Here is my code:
<?php
include("conn.php");
$id=$_GET['id'];
$sql="SELECT * FROM test WHERE id='$id'";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
?>
<script type='text/javascript'>
function formValidator()
{
// Make quick references to our fields
alert("hiiiiiii");
var name = document.getElementById('name').value;
var email = document.getElementById('emailid').value;
var ph = document.getElementById('ph').value;
if( name=="" || name==null)
{
alert("Please Enter user name");
return false;
}
var alphaExp = /^[a-zA-Z]+$/;
if(!name.match(alphaExp))
{
alert("please Enter only Alphabates for Name");
return false;
}
if(email=="" || email=="null")
{
alert("Please Enter Email Address");
return false;
}
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(!email.match(emailExp))
{
alert("please Enter valide email address");
return false;
}
if(ph=="" || ph=="null")
{
alert("Please Enter Phone Number");
return false;
}
var numericExpression = /^[0-9]+$/;
if(!ph.match(numericExpression))
{
alert("Enter only Digit for Phone Number");
return false;
}
}
</script>
<form name="updateform" method="POST" action="update_ind_new.php" onsubmit='return formValidator()'>
<table width="200" border="0">
<tr>
<td>User Name</td>
<td>E-Mail</td>
<td>phno</td>
</tr>
<tr>
<td><label>
<input name="name" type="text" id="name" value=" <?php echo $row['name']; ?>" >
</label></td>
<td><label>
<input name="email" type="text" id="emailid" value=" <?php echo $row['emailid']; ?>" >
</label></td>
<td><label>
<input name="ph" type="text" id="ph" value=" <?php echo $row['phno']; ?>" >
</label></td>
</tr>
<tr>
<td> <input name="id" type="hidden" id="id" value=" <?php echo $row['id']; ?>"></td>
<td><label>
<input type="submit" name="Submit" value="Submit">
</label></td>
<td> </td>
</tr>
</table>
</form>
write
return true;at the end of this line