473,396 Members | 1,879 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.

Ajax validation

250 100+
I have a web page developed using php and postgres. There I have a page for user administration(add user). If user fill all information and click submit button I want to send those values to ajax file and validate and insert to the DB. I passed value to the ajax file and I want to send validated values to php file to insert to the DB. How can I do that? Plase help me.
This is my php file.

Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['submit'])){
  2.     $array = array('FullName'=>'FullName','Gender'=>'Gender','PhnNo' =>'PhoneNumber',    'Email' =>'EmailAddress',);
  3.     foreach ($array as $key => $val)
  4.     $$key = $_POST[$val];
  5.  
  6.         $pgsql = "insert into \"User\" ( \"Name\" ,  \"Phone\" ,  \"PtntEmail\",\"Gender\" )
  7. VALUES ('$FullName',  '$PhnNo',  '$Email','$Gender');"; 
  8.  echo $pgsql;
  9.     $result = pg_query($dbconn , $pgsql);
  10.     if (!$result) {
  11.          die("Error in SQL query: " . pg_last_error());
  12.      }
  13.  
  14.         echo "Data successfully inserted!";
  15.      }
  16.  
  17.     ?>            <form name="user.php" id="user.php" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
  18.                       <tr>
  19.                     <td height="24" colspan="3" ><!--DWLayoutEmptyCell-->&nbsp;</td>
  20.                 </tr>
  21.                   <tr>
  22.                     <td height="24" >Full Name*</td>
  23.                     <td colspan="2"><input type="text" name="FullName"  size="40" ></td>
  24.                   </tr>
  25.  
  26.                   <tr>
  27.                     <td>Gender</td>
  28.                     <td width="69"><input name="Gender" name="Male" type="radio" value="1"/> Male</td>
  29.  
  30.                     <td width="297"  ><input name="Gender" name="Female" type="radio" value="2" />Female&nbsp;</td>
  31.                   </tr>
  32.  
  33.                   <tr>
  34.                     <td>Phone Number*</td>
  35.                     <td colspan="2"><input type="text" name="PhoneNumber" /></td>
  36.                   </tr>
  37.  
  38.                   <tr>
  39.                     <td>Email Address</td>
  40.                     <td colspan="2"><input type="text" name="EmailAddress" /></td>
  41.                   </tr>
  42.  
  43.                   </tr>
  44.  
  45.                   <tr>
  46.                     <td>&nbsp;</td>
  47.                     <td colspan="2" align="right">
  48.  
  49.                 <input id="submit" src="submit.jpg" type="image"  alt="submit" height="30"  width="73" onclick="javascrpit:pages(); return false"  />
  50.  
  51.                     <input id="Cancel" src="Cancel.jpg" type="image"  alt="cancel" height="30"  width="73" />    
  52.  
This is ajax page
Expand|Select|Wrap|Line Numbers
  1. function GetXmlHttpObject() {
  2.     var request;
  3.     try {
  4.         request=new XMLHttpRequest();
  5.     }
  6.     catch (e) {
  7.         try {
  8.             request=new ActiveXObject("Msxml2.XMLHTTP");
  9.         }
  10.           catch (e) {
  11.             try {
  12.                 request=new ActiveXObject("Microsoft.XMLHTTP");
  13.             }
  14.             catch (e) {
  15.                 alert("Your browser does not support AJAX!");
  16.                 return false;
  17.             }
  18.         }
  19.     } 
  20.     return request;
  21. }
  22.  
  23.  
  24. function pages(){
  25. var FullName =document.getElementById('FullName').value;
  26.  
  27. }
  28.  
  29.  
Jul 16 '09 #1
1 2017
It would be probably better to use the form for places like this if there is going to be a bit of data.

This is one of my ajax functions..

Expand|Select|Wrap|Line Numbers
  1. function displayMiningSelectDialog(astID)
  2. {
  3.     miningDialogHttp = getXMLHttp(); 
  4.     if(miningDialogHttp == null)
  5.     {
  6.         alert ("Browser does not support HTTP Requests");
  7.         return;
  8.     }
  9.     var domain = document.domain;
  10.     var url="http://" + domain + "/GAME/PHP/Scan/ScanXMLhttp.php";
  11.     url=url+"?miningDialog=1&astID=" + astID + "&sid="+Math.random();
  12.     miningDialogHttp.open("GET",url,true);
  13.     miningDialogHttp.onreadystatechange=displayMiningSelectDialogResponse;
  14.     miningDialogHttp.send(null);
  15. function displayMiningSelectDialogResponse() 
  16.     if (miningDialogHttp.readyState==4 || miningDialogHttp.readyState=="complete")
  17.     {
  18.         eval(miningDialogHttp.responseText);
  19.     }
  20. }
Jul 16 '09 #2

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

Similar topics

1
by: Mihir | last post by:
Hi There, I've problem while I submit a button where I used AJAX, I created simple page which will search the customer name from database using AJAX. Once I search customer ID i need to search...
1
by: AECL_DEV | last post by:
Hello Everyone, Ive seen alot of people saying that the best way to AJAX Validate a form is through the submit button, because validation should be synchronous. Im wondering, is there any good...
5
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only...
1
by: John Chan | last post by:
Hi, Im doing a maintenance application in ajax and coldfusion at work on IE6 exclusively. I have a save button on each form and i have to do various validations server side and on client side...
3
by: Sandman | last post by:
So, I've used ajax for quite some time for different stuff. Mostly I just feed a funktion I made with the ID of the DIV that should be updated with the output from page XXX.php Now I want to...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
3
rizwan6feb
by: rizwan6feb | last post by:
Hi experts! Recently i was working on "Form Validation Using Ajax". My form validation was creating problem, when a user changes focus too quickly. I had a post related to this, but was unable to...
16
by: ashwinkumar18 | last post by:
hi, am very new to ajax and js . i tried using ajax for server validation in my jsp. i also used js for client side validation i have my js script for client side validation in a seperate file....
3
pradeepjain
by: pradeepjain | last post by:
hii guys , I wanna share a very gud ajax validation script with php... Ajax Form Validation - sForm | chains.ch weblog I am very new to ajax .So i wanna small help....i want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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
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.