473,657 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

250 Contributor
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 2520
dlite922
1,584 Recognized Expert Top Contributor
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
13213
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: Hunter_69. Here is what the form looks like. I have the difficulty of inserting the multiple items selected by the user the first time he visits and uses the screen and then using an UPDATE when he visits later. Model | Original Price | Reduced Price...
1
1407
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: onBlur="isValidInt(this,'Error text',false) But how can I call in case of onSubmit. There I can't use the "this" and the following code doesn't work: isValidInt(document.ageField,'Error text', false);
9
1406
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 also press a post button that post these six numbers into the database. My problem is that these six numbers need to be posted to the database from less to greatest, and all of my code is within the business tier class not the code behind class. ...
1
4227
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 the example to work. I created the following two classes, provided with the example: *-*-**-*-*-*-*-*-*-*-*-*-**-*-*-*-*-CheckBoxColumn Class:-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-**-*-*-*
5
2540
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 I get the error message and my script tries to move the focus to the first item...but because I hit the tab the focus in already on the second item which does not contain a 6 digit value so I must kill the page. help! function CkFrmt(str) {
6
4305
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 have holidays we require our employees to sign up in 4 hr increments for the times we post. I'm having trouble creating a time slot that ends @ 12am. 12pm and all other hours work fine for start/end times. however 12am causes problems. My actual...
4
2590
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 figured since all the panel data is still being sent through the postbacks, instead of using Sessions, or HttpContext, I could just take the values from the textboxes. This all works fine, except for security. I realized that I could inject...
6
2058
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 the 15 and the 303 for (fifteen thousand three hundred and three) it errored function is_number($number) { $text = (string)$number; $textlen = strlen($text);
9
4146
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
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.