473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

250 100+
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) ?
Jun 17 '09 #1
1 2508
dlite922
1,584 Expert 1GB
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
Jun 17 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
1
by: Clevo | last post by:
Hello, I add a javascript check to each input field. I use an onBlur event. But I want to add a "batch check" function to a onSubmit event too. In case of onBlur the call my check like this:...
9
by: Leon | last post by:
I have a webform in which when the user press generate button the form generate six unique ramdon numbers, the user can also type these six numbers in manually in any order. however, the user can...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
5
by: eyoung | last post by:
I have a function to check a string to make sure it is 6 digites using the trigger onBlur="CkFrmt(this)" Problem is I've got 4 fields in a row...if I enter a wrong number in the first and hit tab...
6
by: D | last post by:
Hello all...I have an issue with one of my java script functions that I'm hoping someone can easily help with. I have a web based application that we use to create/sign up for overtime. When we...
4
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
6
by: GarryJones | last post by:
The following function checks to see if a variable read from a mysql database is numeric. The funtion worked until I hit the value 15 303 That is a valid number but because of the space between...
9
by: bizt | last post by:
Hi, I am using the following function to validate a forms value as an integer function isNumeric(str){ var numericExpression = /^+$/; if(str.match(numericExpression)){ return true; }else{
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.