I'm having php page with validation. This is the code.
-
<script language="javascript" src="../javascripts/validate.js"></script>
-
<script type="text/javascript">
-
function valForm(){
-
if(!valid_required(document.add.FullName.value))
-
{
-
add.FullName.style.background = 'Yellow';
-
alert("First name is required field.")
-
return false
-
}
-
}
-
</script>
-
$array = array('FullName'=>'FullName','DoB'=>'date1');
-
-
foreach ($array as $key => $val)
-
$$key = $_POST[$val];
-
-
if(isset($_POST['Submit'])){
-
-
$pgsql = "insert into \"xxx\" ( \"Name\" , \"DateofBirth\" )
-
VALUES ('$FullName', '$DoB');";
-
-
$result = pg_query($dbconn , $pgsql);
-
if (!$result) {
-
die("Error in SQL query: " . pg_last_error());
-
}
-
echo "Data successfully inserted!";
-
}
-
}
-
<form action="Add.php" method="post" name="add" onSubmit="return valForm()" >
-
<tr>
-
<td height="24" colspan="3" ><!--DWLayoutEmptyCell--> </td>
-
</tr>
-
<tr>
-
<td height="24" >Full Name*</td>
-
<td colspan="2"><input type="text" name="FullName" size="40"/></td>
-
</tr>
-
<tr>
-
<td>Date of Birth*</td></tr>
-
<input name="Submit" value="Submit" id="Submit" src="../common/images/Submit.jpg" type="image" alt="add" height="30" width="73" onclick="Validator();"/>
-
I want to adda values after validation is completed. In my code when I click submit button it tries to insert values and didnt get any error message. How can I check if function is true then insert value(execute insert query) ?