<?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;
$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
}
}