php入门(3) QtQuick最简单的注册系统

来源:互联网 发布:snmp软件下载 编辑:程序博客网 时间:2024/06/18 09:07
<?php// 账号登录验证function tableIsExits($tablesName, $findtablename){    $result = mysql_query("SHOW TABLES FROM $tablesName");    $i = mysql_num_rows($result);    if ($i < 1) {        return false;    }    for ($x = 0; $x < $i; $x ++) {        $ret = mysql_table_name($result, $x);        if ($ret == $findtablename) {            return true;        }    }    return false;}// 选则表单class zhClass{    public $zh;    // 账号    public $mm;    // 密码    public $con;    // 数据库句柄    public function checkZh() // 检测账号是否存在    {        $result = mysql_query("SELECT * FROM teacher WHERE id=$this->zh");        if (mysql_num_rows($result) != 0) {            return true;        } else {            return false;        }    }    public function __construct() // 构造函数 连接到数据库 打开账号数据表    {        $this->con = mysql_connect("localhost", "root", "root");        mysql_query("set names 'utf8'");        if (! $this->con) {            die('连接服务器失败: ' . mysql_error());        } else {            mysql_select_db("mytest", $this->con);        }    }    function logging($id, $mm) // 登录    {        $this->zh = $id;        $this->mm = $mm;        if (! $this->checkZh()) {            return false;        }        // 判断字段是否存在        $result = mysql_query("SELECT * FROM teacher WHERE id=$id");        if (mysql_num_rows($result) != 0) {            $row = mysql_fetch_array($result);            $m_mima = $row['mima'];            $name = $row['name'];            if ($mm == $m_mima) {                echo "登录成功";                return true;            } else {                echo "密码错误";            }        } else {            echo "登录失败";        }        return false;    }    function _ChangeUserName($mid, $mm, $newName)    {        $this->zh = $mid;        $this->mm = $mm;        if (! $this->checkZh()) {            echo "账号不存在!";            return false;        }        if (! $this->logging($mid, $mm)) {            return false;        }         echo  $newName . "," . $mm;         //传过来的是字符串 但是数据库不识别 加上两个单引号转为字符串 '$newName'       $ret=  mysql_query("UPDATE teacher SET name='$newName' WHERE id=$mid");       if(!$ret)        {           echo " 无法修改用户昵称 ";       }    }    public function   Reg($zh,$mima,$nichen)    {        $this->zh = $zh;        $this->mm = $mima;        if ($this->checkZh())        {            echo "账号已存在";            return  ;        }        if(mysql_query("INSERT INTO teacher (name,id,mima) VALUES ('$nichen',$zh,'$mima')")==false)        {            echo "注册失败" ;        }else{            echo "注册成功";        }    }    public function __destruct() // 析构函数销毁数据库连接    {        mysql_close($this->con);    }}$pcode = $_GET['code'];$obj = json_decode($pcode);echo  $pcode . "," . $obj->pwd;$pobj = new zhClass();if ($obj->type == 0) {    $pobj->logging($obj->id, $obj->pwd);}elseif($obj->type==1){    echo "尝试修改昵称**";    $pobj->_ChangeUserName($obj->id, $obj->pwd, $obj->_newName);}elseif ($obj->type==2){    $pobj->Reg($obj->id, $obj->pwd, $obj->_newName);}?>
ApplicationWindow {    visible: true    width: 640    height: 480    title: qsTr("Hello World")    //注册    function  regFunc()    {        var  x = new XMLHttpRequest();        x.onreadystatechange =function()        {            if(x.readyState == 4) {                if(x.status == 200) {                    console.log("The server replied with: " + x.responseText);                    txt.text = x.responseText;                }            }        };        var xxx = new Object;        xxx.id=289672082;        xxx.pwd = '12345';        xxx._newName='阿央0705';        xxx.type=2;      var pcode=  JSON.stringify(xxx);       x.open("GET","http://localhost/mycode/Test/index.php?code="+pcode);        x.send(null);    }    function  logging()    {                var  x = new XMLHttpRequest();                x.onreadystatechange =function()                {                    if(x.readyState == 4) {                        if(x.status == 200) {                            console.log("The server replied with: " + x.responseText);                            txt.text = x.responseText;                        }                    }                };                var xxx = new Object;                xxx.id=289672082;                xxx.pwd = '12345';                xxx.type=0;              var pcode=  JSON.stringify(xxx);               x.open("GET","http://localhost/mycode/Test/index.php?code="+pcode);                x.send(null);    }        function _ChangeName()        {            var  x = new XMLHttpRequest();            x.onreadystatechange =function()            {                if(x.readyState == 4) {                    if(x.status == 200) {                        console.log("The server replied with: " + x.responseText);                        txt.text = x.responseText;                    }                }            };            var xxx = new Object;            xxx.id=289672082;            xxx.pwd = '12345';            xxx.type=1;            xxx._newName='沫、D';          var pcode=  JSON.stringify(xxx);           x.open("GET","http://localhost/mycode/Test/index.php?code="+pcode);            x.send(null);        }    Component.onCompleted: {         regFunc();    }    Text {        id: txt        text: qsTr("text")        textFormat: Text.RichText    }    //UPDATE `teacher` SET `name`='hello'  WHERE  id=12}
0 0
原创粉丝点击