<?php
//?賬號(hào)登錄驗(yàn)證
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;
????//?賬號(hào)
????public?$mm;
????//?密碼
????public?$con;
????//?數(shù)據(jù)庫(kù)句柄
????public?function?checkZh()?//?檢測(cè)賬號(hào)是否存在
????{
????????$result?=?mysql_query("SELECT?*?FROM?teacher?WHERE?id=$this->zh");
????????if?(mysql_num_rows($result)?!=?0)?{
????????????return?true;
????????}?else?{
????????????return?false;
????????}
????}
????public?function?__construct()?//?構(gòu)造函數(shù)?連接到數(shù)據(jù)庫(kù)?打開(kāi)賬號(hào)數(shù)據(jù)表
????{
????????$this->con?=?mysql_connect("localhost",?"root",?"root");
????????mysql_query("set?names?'utf8'");
????????if?(!?$this->con)?{
????????????die('連接服務(wù)器失敗:?'?.?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?"密碼錯(cuò)誤";
????????????}
????????}?else?{
????????????echo?"登錄失敗";
????????}
????????return?false;
????}
????function?_ChangeUserName($mid,?$mm,?$newName)
????{
????????$this->zh?=?$mid;
????????$this->mm?=?$mm;
????????if?(!?$this->checkZh())?{
????????????echo?"賬號(hào)不存在!";
????????????return?false;
????????}
????????if?(!?$this->logging($mid,?$mm))?{
????????????return?false;
????????}
?????????echo??$newName?.?","?.?$mm;
?????????//傳過(guò)來(lái)的是字符串?但是數(shù)據(jù)庫(kù)不識(shí)別?加上兩個(gè)單引號(hào)轉(zhuǎn)為字符串?'$newName'
???????$ret=??mysql_query("UPDATE?teacher?SET?name='$newName'?WHERE?id=$mid");
???????if(!$ret)?
???????{
???????????echo?"?無(wú)法修改用戶(hù)昵稱(chēng)?";
???????}
????}
????public?function???Reg($zh,$mima,$nichen)
????{
????????$this->zh?=?$zh;
????????$this->mm?=?$mima;
????????if?($this->checkZh())
????????{
????????????echo?"賬號(hào)已存在";
????????????return??;
????????}
????????if(mysql_query("INSERT?INTO?teacher?(name,id,mima)?VALUES?('$nichen',$zh,'$mima')")==false)
????????{
????????????echo?"注冊(cè)失敗"?;
????????}else{
????????????echo?"注冊(cè)成功";
????????}
????}
????public?function?__destruct()?//?析構(gòu)函數(shù)銷(xiāo)毀數(shù)據(jù)庫(kù)連接
????{
????????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?"嘗試修改昵稱(chēng)**";
????$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")
????//注冊(cè)
????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
}