Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old June 17th, 2009, 06:53 AM
Familiar Sight
 
Join Date: Jan 2008
Posts: 196
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) ?

Last edited by Atli; June 17th, 2009 at 12:26 PM. Reason: Changed the [quote] tags to [code] tags.
  #2  
Old June 17th, 2009, 07:01 AM
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,075

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop (if statement) is not working properly when the condition is true robin1983 answers 1 August 18th, 2008 08:49 AM
Access expoert reports to PDF using PDF writer 6.0 issues Grasshopper answers 11 November 13th, 2005 07:08 AM
How do I create pdf reports from Access? dog answers 7 November 13th, 2005 07:06 AM
Why must I use PrtDevMode Randy Harris answers 5 November 12th, 2005 04:11 PM