wxml文件:

<view class='container'>
  <view class='img'>
    <image src='../images/index.jpg'></image>
  </view>
<view class='login'>
<input class='userName' placeholder='用户名' confirm-type='next' bindblur='username'></input>
<input class='passWord' placeholder='密码' password='ture' confirm-type='done' bindblur='userpassword'></input>
<button type='primary' bindtap='login' class='denglu-btn'>登录</button>
<button bindtap='reset' style='margin-top: 30rpx;border-radius: 70rpx;' plain="true">找回密码</button>
</view>
</view>

wxss文件:

.container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 50rpx 0;
  box-sizing: border-box;
}
.denglu-btn {
  margin-top: 30rpx;
  border-radius: 70rpx;
  box-shadow: 0rpx 5rpx 20rpx #ccc;
}
.login {
  margin-top: 100rpx;
}
.userName {
  margin-top: 50rpx;
  background-color: rgb(228, 240, 186);
  border-radius: 15rpx;
  height: 70rpx;
}
.passWord {
  margin-top: 50rpx;
  background-color: rgb(228, 240, 186);
  border-radius: 15rpx;
  height: 70rpx;
}
.img {
  width: 100%;
}
image {
  width: 100%;
}
input {
  text-align: center;
}

js文件:

Page({
  data: {
    name: "",
    password: ""
  },
  username: function(n) {
    this.setData({
      name: n.detail.value
    })
  },
  userpassword: function(n) {
    this.setData({
      password: n.detail.value
    })
  },
  reset: function() {
    wx.navigateTo({
      url: '../resetpassword/resetpassword',
    })
  },
  login: function() {
    var that = this;
    wx.request({
      url: 'https://www.111111.com/111.php',
      method: "post",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        type: "denglu",
        name: that.data.name,
        password: that.data.password,
      },
      success(res) {
        // console.log(res.data)
        if (res.data == 11) {
          wx.showToast({
            title: '登录成功',
            icon: 'success',
            success: wx.navigateTo({
              url: '../teach_index/teach_index',
            })
          })
          var app = getApp(); // 取得全局App
          app.globalData.name = that.data.name // 取得全局变量需要的值
        } else if (res.data == 21) {
          wx.showToast({
            title: '登录成功',
            icon: 'success',
            success: wx.navigateTo({
              url: '../stu_index/stu_index',
            })
          })
          var app = getApp(); // 取得全局App
          app.globalData.name = that.data.name // 取得全局变量需要的值
        } else {
          wx.showToast({
            title: "用户名或密码错误",
            icon: 'none',
          })
        }
      }
    })
  }
})

app.js文件:

  globalData: {
    name: '', //由注册界面传入数据
  }

后台PHP文件:

if($type=="denglu")
{
	function denglu(){
		$post_name =$_POST["name"];
		$post_password= $_POST["password"];
		$con = mysqli_connect("localhost","root","数据库密码") or die("数据库连接失败");//连接数据库
		mysqli_query($con,"set names utf8");
		mysqli_select_db($con,"stu") or die("数据库选择失败");
		$sql="SELECT name,password,level from user where name = '$_POST[name]' and password ='$_POST[password]'";
		$result= mysqli_query($con,$sql);
		$num = mysqli_num_rows($result);
		if ($num){
			echo "1";
			}
		else{echo "该用户不存在";}
	}
	denglu();
}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注