apicloud mysql 登录_PHP+MySQL实现前台的登陆注册。

前台的注册页面

title

html,

body {

height: 100%;

}

.row {

position: relative;

box-sizing: border-box;

width: auto;

height: 70px;

margin-left: 32px;

margin-right: 32px;

padding-top: 40px;

border-bottom: 1px solid #888;

}

.input {

width: 100%;

height: 20px;

border: none;

font-size: 20px;

}

.button {

position: relative;

margin-left: 32px;

margin-right: 32px;

margin-top: 32px;

width: auto;

height: 50px;

background-color: #e3007f;

color: #fff;

font-size: 24px;

line-height: 50px;

text-align: center;

border-radius: 8px;

}

.highlight {

opacity: 0.7;

}

注册

apiready = function() {

};

下面是从php接口取出数据并判断。

function fnRegister() {

var uname = $api.byId('userName').value,

pwd = $api.byId('password').value;

phone = $api.byId('phone').value;

api.ajax({

url:'http://192.168.0.117/APIcloud-PHP/PHP/register.php',//如果地址访问不到会请求出错,请填写自己的接口地址

method:'post',

cache:'false',

timeout:5,

dataTpye:'json',

data:{

values:{

uname: uname,

pwd: pwd,

phone: phone

}

}

},function(ret,err){

if (ret.status==1 && ret.num<1) {//各种条件都符合标准的话,注册成功。

alert(ret.msg);

api.execScript({  将注册成功的用户名传到登陆页面。

name: 'login',

frameName: 'login_frame',

script: 'fnSetUserName("' + ret.uname + '");'

});

api.closeWin();

}else if(ret.num>=1) {//   num 是根据你注册的时候输入的用户名,在后台查询有没有同样的用户名,如果从后台传过来的num值大于等于一是用户名已存在。

alert(ret.msg);

}else if(ret.status==2){//   status是后台判断用户填写的注册信息的完整性,如果有信息没有填写会提示“用户信息不完整”。

alert(ret.msg);

}

});

};

注册的php接口

header("content-type:text/html;charset=utf-8");

$dsn = "mysql:host=localhost;dbname=apicloud";

$user = "root";

$pwd = "";

$pdo = new PDO($dsn,$user,$pwd,array(PDO::ATTR_PERSISTENT=>TRUE));

$pdo->exec("set names utf8");

$uname = trim($_POST['uname']);

$pwd = md5($_POST['pwd']);

$phone = trim($_POST['phone']);

if($uname==""||$pwd==""||$phone==""){

$msg[] = "用户名信息不完整";

$status[] = "2";

$list['msg'] = $msg;

$list['status'] = $status;

echo json_encode($list);

exit;

}

$data = "select * from uname where uname='$uname'";

$res = $pdo->prepare($data);

//$res->exec();

$res->execute();

$num = $res->rowCount();

if($num>=1){

$msg[] = "用户名已存在,请更换用户名";

$status[] = "1";

$list['msg'] = $msg;

$list['num'] = $num;

$list['status'] = $status;

echo json_encode($list);

exit;

}

$sql = "insert into uname (uname, pwd, phone) values ('$uname', '$pwd', '$phone')";

$result=$pdo->query($sql);

if($result){

$status[] = "1";

$msg[] = "注册成功";

$list['status'] = $status;

$list['msg'] = $msg;

$list['data'] = $result;

$list['uname'] = $uname;

$list['num'] = $num;

echo json_encode($list);

}else{

$status[] = "0";

$msg[] = "注册失败,请重试";

$list['status'] = $status;

$list['msg'] = $msg;

echo json_encode($list);

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值