Use ajax in PHP to log on to the page, verify whether the user name is available, and dynamically call the database.

Source: Internet
Author: User

Use ajax in PHP to log on to the page, verify whether the user name is available, and dynamically call the database.

1. Basic ajax knowledge

Ajax is a comprehensive application technology integrated with jquery, php, and other technologies, not new content. Ajax is also written in the <script> label.

If ajax is used, there must be one processing page. The processing page only operates the database and returns the value. The pages are all processed by ajax.

2. Use ajax as the login page denglu. php

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Login processing page dengluchuli. php

<?php$uid = $_POST["u"];$pwd = $_POST["p"];include("./DBDA.class.php");$db = new DBDA();$sql = "select password from login where username='{$uid}'";$mm = $db->StrQuery($sql,0);if($mm == $pwd && $pwd!=""){    echo "OK";}else{    echo "NO";}

3. Use ajax to verify whether the user name is available in testuid. php

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Processing page uidchuli. php

<?php$uid = $_POST["u"];include("./DBDA.class.php");$db = new DBDA();$sql = "select count(*) from login where username='{$uid}'";echo $db->StrQuery($sql,0);

Effect

4. dynamically call the database. Enter keywords in the search box. keywords in the content are automatically displayed in the input box.

List. php

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Processing page listchuli. php

<?php$name = $_POST["n"];include("./DBDA.class.php");$db = new DBDA();$sql = "select areaname from chinastates where areaname like'%{$name}%'";echo $db->StrQuery($sql,0);

Effect

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.