search

Home  >  Q&A  >  body text

I followed the teacher’s code but kept reporting this error: 500 (Internal Server Error)

//登录(html)
function dologin(){
			var username = $.trim($('#username').val());
			var password = $.trim($('#password').val());
			var verifycode = $.trim($('#verifycode').val());
			if(username == ''){
				layer.alert('请输入用户名',{icon:2});
				return;
			}
			if(password == ''){
				layer.alert('请输入密码',{icon:2});
				return;
			}
			if(verifycode==''){
				layer.alert('请输入验证码',{icon:2});
				return;
			}
			$.post('/admins.php/admins/Account/dologin',{'username':username,'password':password,'verifycode':verifycode},function(res){
				if(res.code>0){
					reloadImg();
					layer.alert(res.msg,{icon:2});
				}else{
					layer.msg(res.msg);
					setTimeout(function(){window.location.href = '/admins.php/admins/Home/index'},1000);
				}
			},'json')
			
//控制器(controller)
public function dologin(){
		$username = trim(input('post.username'));
		$pwd = trim(input('post.password'));
		$verifycode = trim(input('post.verifycode'));

		if($username == ''){
			exit($res = json_encode(array('code'=>1,'msg'=>'用户名不能为空')));
		}
		if($pwd == ''){
			exit($res = json_encode(array('code'=>1,'msg'=>'密码不能为空')));
		}
		if($verifycode == ''){
			exit($res = json_encode(array('code'=>1,'msg'=>'请输入验证码')));
		}
		// 验证验证码
		if(!captcha_check($verifycode)){
			exit($res = json_encode(array('code'=>1,'msg'=>'验证码错误')));
		}
		// 验证用户
		$this->db = new Sysdb;
		$admin = $this->db->table('admins')->where(array('username'=>$username))->item();
		if(!$admin){
			exit($res = json_encode(array('code'=>1,'msg'=>'用户不存在')));
		}
		if(md5($admin['username'].$pwd) != $admin['password']){
			exit($res = json_encode(array('code'=>1,'msg'=>'密码错误')));
		}
		if($admin['status'] == 1){
			exit($res = json_encode(array('code'=>1,'msg'=>'用户已被禁用')));
		}
		// 设置用户session
		session('admin',$admin);
		exit($res = json_encode(array('code'=>0,'msg'=>'登录成功')));
	}			
			
			
			
			
			
			
			
			
			
			


帅气的勇士帅气的勇士2194 days ago1645

reply all(2)I'll reply

  • 驱魔鮔

    驱魔鮔2019-01-02 20:36:57

    Hello, would you like to ask, has your problem been solved? I also have a problem. There is no response when I click OK. The console displays 404 not found


    reply
    0
  • 帅气的勇士

    Solved. I kept reporting 500 errors. I always thought there was a problem with the server. Later, I carefully checked the code and found that the code was written incorrectly. I suggest you check your own code carefully and don’t miss a letter. Be patient.

    帅气的勇士 · 2019-01-02 20:56:43
    驱魔鮔

    I did write the code in the background wrong, thank you.

    驱魔鮔 · 2019-01-20 14:56:29
  • Cancelreply