Landing Interface Ajax Instance application

Source: Internet
Author: User

Building MYDBDA Database Encapsulation class

mydbda.php

<?PHPclassMydbda {var $host= "localhost"; var $username= "Root"; var $password= "123"; var $database= "MyDB"; /** Function: Execute SQL statement, return result parameter: $sql: SQL statement to execute $type: type of SQL statement, CX for query, QT for other $data: The database return value to manipulate: if it is a query, returns the result set if it is another statement, the execution returns OK successfully, the failure returns no*/        functionSelect ($sql,$type,$data)        {                        //1. Making Connection Objects            $db=NewMysqli ($this->host,$this->username,$this->password,$data); //2. Determine if the connection is successful            if(Mysqli_connect_error())            {                    Echo"Connection Failed"; //exit the entire program                Exit; }            Else            {                //4. Execute SQL statements                                $result=$db->query ($sql); if($type= = "CX")                {                    $str= "";  while($row=$result-Fetch_row ()) {                         for($i= 0;$i<Count($row);$i++)                        {                            $str=$str.$row[$i]." ^"; }                        $str=substr($str, 0,strlen($str)-1); $str=$str."|"; }                    $str=substr($str, 0,strlen($str)-1); return $str; }                Else                {                    if($result)                    {                        return"OK"; }                    Else                    {                        return"NO"; }                }                                    }        }                }?>

Processing Interface Source Code

chuli.php

<?PHPinclude("mydbda.php");/*$uid = $_post["UID"]; $pwd = $_post["pwd"];//1. Connect object $db = new mysqli ("localhost", "root", "123", "MyDB");        2. Determine if the connection succeeded if (Mysqli_connect_error ()) {echo "Connection failed"; Exit the entire program exit;}        else{$sql = "SELECT count (*) from login where Username= '". $uid. "' and password= '". $pwd. "'";        $result = $db->query ($sql);        $row = $result->fetch_row ();    if ($row [0]==0) {echo "Username or password error";    } else {echo "OK"; }}*/$uid=$_post["UID"];$db=NewMydbda ();$sql= "SELECT count (*) from login where Username= '".$uid."‘";$str=$db->select ($sql, "CX", "MyDB");Echo $str;?>

Main interface Source code

testajax.php

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >User name:<input type= "text" id= "Uidz"/><div style= "color:red" id= "xs" ></div></body><script type= " Text/javascript ">$ (document). Ready (function(e) {$ ("#uidz"). Blur (function(){            varUID = $ (this).Val (); $.Ajax ({URL: "Chuli.php",Data: {Uid:uid},DataType: "TEXT",type: "POST",Success:function(data) {if(data== "1")                        {                            $("#xs"). Text ("The user name already exists!") "); }                        Else                        {                            $("#xs"). Text ("");                        }                                        }                                }); })            $("#btn"). Click (function(){                    varUID = $ ("#uid").Val (); varPWD = $ ("#pwd").Val (); $.Ajax ({URL: "Chuli.php",Data: {uid:uid,pwd:pwd},type: "POST",DataType: "TEXT",Success:function(data) {if(data = = "OK") {window. location = "index.php"; }                            Else{alert (data);                        }                                                }                                }); })        });</script>

Landing Interface Ajax Instance application

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.