2 ler 123 ler_123 于 2017.01.12 16:54 提问

thinkphp登录连接数据库验证时出现404错误

错误界面
图片说明

html

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="">
  <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="">

  <title>泡车堂登录</title>

  <!-- Bootstrap core CSS -->
  <link href="/carProject/Public/css/bootstrap.min.css" rel="stylesheet">




  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>

  <![endif]-->
</head>

<body>
<div class="container" id="d1">
  <div class="row">
    <div class="col-sm-6 col-sm-offset-3 form-box">
      <div class="form-top">
        <h2>泡车堂商户PAD版</h2>
      </div>
      <div class="form-bottom">
        <form role="form" method="post" class="login-form">
          <div class="form-group">
            <label class="sr-only" >用户名</label>
            <input type="text" name="username" placeholder="请输入您的用户名" class="form-control" required>
          </div>
          <div class="form-group">
            <label class="sr-only" >密码</label>
            <input type="password" name="password" placeholder="请输入您的密码" class="form-control" required>
          </div>
          <button type="button" class="btn btn-primary btn-block" onclick="login.check()">登录</button>
        </form>
      </div>
    </div>
  </div>
</div>

<script type="text/javascript">
    function autoHeight(){
        var winHeight=0;
        if (window.innerHeight)
            winHeight = window.innerHeight;
        else if ((document.body) && (document.body.clientHeight))
            winHeight = document.body.clientHeight;
        if (document.documentElement && document.documentElement.clientHeight)
            winHeight = document.documentElement.clientHeight;
        document.getElementById("d1").style.marginTop= winHeight/3 +"px";
    }
    autoHeight();
    window.onresize = autoHeight;
</script>

<script src="/carProject/Public/js/jquery.js"></script>
<script src="/carProject/Public/js/dialog/layer.js"></script>
<script src="/carProject/Public/js/dialog.js"></script>
<script src="/carProject/Public/js/admin/login.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
</body>
</html>

login.js

var login = {
    check : function() {
        // 获取登录页面中的用户名 和 密码
        var username = $('input[name="username"]').val();
        var password = $('input[name="password"]').val();

        if(!username) {
            dialog.error('用户名不能为空');
        }

        if(!password) {
            dialog.error('密码不能为空');
        }

        var url = "/carProject/index.php?m=admin&c=login&a=check";
        var data = {'username':username,'password':password};
        // 执行异步请求  $.post
        $.post(url,data,function(result){
            if(result.status == 0) {
                return dialog.error(result.message);
            }
            if(result.status == 1) {
                return dialog.success(result.message, 'https://www.baidu.com/');
            }

        },'JSON');

    }
}

AdminModel.class.php

 <?php
namespace Common\Model;
use Think\Model;


class AdminModel extends Model {
    private $_db = '';

    public function __construct() {
        $this->_db = M('Admin');
    }

    public function getAdminByUsername($username='') {
        $res = $this->_db->where('name="'.$username.'"')->find();
        return $res;
    }


}

LoginController.class.php

 <?php
namespace Admin\Controller;
use Think\Controller;

/**
 * use Common\Model 这块可以不需要使用,框架默认会加载里面的内容
 */
class LoginController extends Controller {

    public function index(){
        $this->display();
    }

    public function check() {
        $username = $_POST['username'];
        $password = $_POST['password'];
        if(!trim($username)) {
            return show(0,'用户名不能为空');
        }

        if(!trim($password)) {
            return show(0,'密码不能为空');
        }

        print_r(C('DB_TYPE'));
        //导入当前项目下面的Model/AdminModel.class.php文件,然后实例化AdminModel类
        $ret = D('Admin')->getAdminByUsername($username);
        print_r($ret);
        /*
        if(!$ret) {
            return show(0,'该用户不存在');
        }

        if($ret['pwd'] != getMd5Password($password)) {
            return show(0,'密码错误');
        }


        session('adminUser', $ret);
        return show(1,'登录成功');*/


    }



}

对数据库的配置

config.php

 <?php
return array(
    //'配置项'=>'配置值'

    //URL地址不区分大小写
    'URL_CASE_INSENSITIVE' =>true,
    'URL_MODEL'=>0,
    'LOAD_EXT_CONFIG' => 'db',
    'MD5_PRE' => 'sing_cms',
    'HTML_FILE_SUFFIX' => '.html',
);

db.php

 <?php
return array(

    'DB_TYPE' => 'mysql',
    'DB_HOST' => '127.0.0.1',
    'DB_USER' => 'root',
    'DB_PWD' => '111111',
    'DB_PORT' => 3366,
    'DB_NAME' => 'demo',
    'DB_CHARSET' => 'utf8',
    'DB_PREFIX' =>'t_',
);

4个回答

ler_123
ler_123   2017.01.12 17:07

提示这个错误:Access denied for user 'root'@'localhost'
但是我已经改了自己的密码了啊

ler_123
ler_123   2017.01.12 17:19

图片说明
贴一个更细致的错误图片

xionglangs
xionglangs   Rxr 2017.01.13 09:52

你登陆的url竟然没有端口。

qq_16877261
qq_16877261   2017.01.13 15:28

数据库配置错误啊,检查你的 数据库用户名和密码是否正确

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!