Connecting Tech Pros Worldwide Forums | Help | Site Map

How to check validate function value is true and then insert the values to database

Familiar Sight
 
Join Date: Jan 2008
Posts: 199
#1: Jun 17 '09
I'm having php page with validation. This is the code.

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" src="../javascripts/validate.js"></script>
  2. <script type="text/javascript">
  3.     function valForm(){
  4.         if(!valid_required(document.add.FullName.value))
  5.         {
  6.         add.FullName.style.background = 'Yellow';
  7.         alert("First name is required field.")
  8.         return false
  9.         }
  10.     }
  11. </script>
  12. $array = array('FullName'=>'FullName','DoB'=>'date1');
  13.  
  14.        foreach ($array as $key => $val)
  15.     $$key = $_POST[$val];
  16.  
  17.     if(isset($_POST['Submit'])){
  18.  
  19.     $pgsql = "insert into \"xxx\" ( \"Name\" , \"DateofBirth\"  )
  20. VALUES ('$FullName', '$DoB');"; 
  21.  
  22. $result = pg_query($dbconn , $pgsql);
  23.     if (!$result) {
  24.          die("Error in SQL query: " . pg_last_error());
  25.      }
  26.     echo "Data successfully inserted!";
  27.        }
  28. }
  29. <form action="Add.php" method="post" name="add"  onSubmit="return valForm()" >
  30.                   <tr>
  31.                     <td height="24" colspan="3" ><!--DWLayoutEmptyCell-->&nbsp;</td>
  32.                 </tr>
  33.                   <tr>
  34.                     <td height="24" >Full Name*</td>
  35.                     <td colspan="2"><input type="text" name="FullName"  size="40"/></td>
  36.                   </tr>
  37.                   <tr>
  38.                     <td>Date of Birth*</td></tr>
  39. <input name="Submit" value="Submit" id="Submit" src="../common/images/Submit.jpg" type="image"  alt="add" height="30"  width="73" onclick="Validator();"/>
  40.  
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) ?

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#2: Jun 17 '09

re: How to check validate function value is true and then insert the values to database


what do you mean you want to add values after validation is completed?

You need some PHP MySQL Form tutorials. Get that working, then modify it to suit your needs.



Dan
Reply