Professional Documents
Culture Documents
HOME
HTML
CSS
JAVASCRIPT
JQUERY
XML
ASP.NET
PHP
SQL
MORE...
REFERENCES
EXAMPLES
FORUM
PHP Basic
PHP HOME PHP Intro PHP Install PHP Syntax PHP Variables PHP Echo / Print PHP Data Types PHP String Functions PHP Constants PHP Operators PHP If...Else...Elseif PHP Switch PHP While Loops PHP For Loops PHP Functions PHP Arrays PHP Sorting Arrays PHP Superglobals
Search w3schools.com
Select Language
WEB HOSTING
UK Reseller Host
Next Chapter
WEB BUILDING
FREE Website C re
W3SCHOOLS EXA
Example
Lois Griffin
Firstname Lastname Age Hometown Job
SHARE THIS PA
PHP Forms
PHP Form Handling PHP Form Validation PHP Form Required PHP Form URL/E-mail PHP Form Complete
Lois
Griffin
40
Newport
Piano Teacher
PHP Advanced
PHP Arrays Multi PHP Date PHP Include PHP File PHP File Upload PHP Cookies PHP Sessions PHP E-mail PHP Secure E-mail PHP Error PHP Exception PHP Filter
1 2 3 4
41 40 39 41
PHP Database
PHP MySQL Intro PHP MySQL Connect PHP CREATE DB/Table PHP INSERT INTO PHP SELECT PHP WHERE PHP ORDER BY PHP UPDATE PHP DELETE PHP ODBC
PHP XML
XML Expat Parser XML DOM XML SimpleXML
PHP Examples
< h t m l > < h e a d > < s c r i p t > f u n c t i o ns h o w U s e r ( s t r ) { i f( s t r = = " " ) { d o c u m e n t . g e t E l e m e n t B y I d ( " t x t H i n t " ) . i n n e r H T M L = " " ; r e t u r n ; } i f( w i n d o w . X M L H t t p R e q u e s t ) { / /c o d ef o rI E 7 + ,F i r e f o x ,C h r o m e ,O p e r a ,S a f a r i x m l h t t p = n e wX M L H t t p R e q u e s t ( ) ; } e l s e { / /c o d ef o rI E 6 ,I E 5 x m l h t t p = n e wA c t i v e X O b j e c t ( " M i c r o s o f t . X M L H T T P " ) ; } x m l h t t p . o n r e a d y s t a t e c h a n g e = f u n c t i o n ( ) { i f( x m l h t t p . r e a d y S t a t e = = 4& &x m l h t t p . s t a t u s = = 2 0 0 ) { d o c u m e n t . g e t E l e m e n t B y I d ( " t x t H i n t " ) . i n n e r H T M L = x m l h t t p . r e s p o n s e T e x t ; } } x m l h t t p . o p e n ( " G E T " , " g e t u s e r . p h p ? q = " + s t r , t r u e ) ; x m l h t t p . s e n d ( ) ; } < / s c r i p t > < / h e a d > < b o d y >
WEB RESOURC
Web Statistics
Web Validation
http://www.w3schools.com/php/php_ajax_database.asp
1/3
1/28/2014
PHP Examples PHP Quiz PHP Certificate
PHP Reference
PHP Array PHP Calendar PHP Date PHP Directory PHP Error PHP Filesystem PHP Filter PHP FTP PHP HTTP PHP Libxml PHP Mail PHP Math PHP Misc PHP MySQLi PHP SimpleXML PHP String PHP XML PHP Zip PHP Timezones
< ? p h p $ q=i n t v a l ( $ _ G E T [ ' q ' ] ) ; $ c o n=m y s q l i _ c o n n e c t ( ' l o c a l h o s t ' , ' p e t e r ' , ' a b c 1 2 3 ' , ' m y _ d b ' ) ; i f( ! $ c o n ) { d i e ( ' C o u l dn o tc o n n e c t :'.m y s q l i _ e r r o r ( $ c o n ) ) ; } m y s q l i _ s e l e c t _ d b ( $ c o n , " a j a x _ d e m o " ) ; $ s q l = " S E L E C T*F R O Mu s e rW H E R Ei d=' " . $ q . " ' " ; $ r e s u l t=m y s q l i _ q u e r y ( $ c o n , $ s q l ) ; e c h o" < t a b l eb o r d e r = ' 1 ' > < t r > < t h > F i r s t n a m e < / t h > < t h > L a s t n a m e < / t h > < t h > A g e < / t h > < t h > H o m e t o w n < / t h > < t h > J o b < / t h > < / t r > " ; w h i l e ( $ r o w=m y s q l i _ f e t c h _ a r r a y ( $ r e s u l t ) ) { e c h o" < t r > " ; e c h o" < t d > ".$ r o w [ ' F i r s t N a m e ' ]." < / t d > " ; e c h o" < t d > ".$ r o w [ ' L a s t N a m e ' ]." < / t d > " ; e c h o" < t d > ".$ r o w [ ' A g e ' ]." < / t d > " ; e c h o" < t d > ".$ r o w [ ' H o m e t o w n ' ]." < / t d > " ; e c h o" < t d > ".$ r o w [ ' J o b ' ]." < / t d > " ; e c h o" < / t r > " ; } e c h o" < / t a b l e > " ; m y s q l i _ c l o s e ( $ c o n ) ; ? >
Explanation: When the query is sent from the JavaScript to the PHP file, the following happens: 1. PHP opens a connection to a MySQL server 2. The correct person is found 3. An HTML table is created, filled with data, and sent back to the "txtHint" placeholder
Previous
Next Chapter
http://www.w3schools.com/php/php_ajax_database.asp
2/3
1/28/2014
Top 10 Tutorials
HTML Tutorial HTML5 Tutorial C SS Tutorial C SS3 Tutorial JavaScript Tutorial jQuery Tutorial SQL Tutorial PHP Tutorial ASP.NET Tutorial XML Tutorial
Top 10 References
HTML/HTML5 Reference C SS 1,2,3 Reference C SS 3 Browser Support JavaScript HTML DOM XML DOM PHP Reference jQuery Reference ASP.NET Reference HTML C olors
Top 10 Examples
HTML Examples C SS Examples JavaScript Examples HTML DOM Examples PHP Examples jQuery Examples XML Examples XML DOM Examples ASP Examples SVG Examples
Web Certificates
HTML C ertificate HTML5 C ertificate C SS C ertificate JavaScript C ertificate jQuery C ertificate XML C ertificate ASP C ertificate PHP C ertificate
Color Picker
R EPO R T ER R O R
HO ME |
TO P
PR INT
FO R UM
ABO UT
W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. C opyright 1999-2014 by Refsnes Data. All Rights Reserved.
http://www.w3schools.com/php/php_ajax_database.asp
3/3