代码如下 <?php
//预先定义数据库连接参数,参数名字自己起的
$host = '127.0.0.1';
$user = 'root';
$psw = 'root';
$dbname = 'blog';
//连接到数据库
$mysqli = new mysqli($host,$user,$psw,$dbname);
//检查是否成功
if($mysqli->connect_errno<>0){
echo "连接失败";
//输出失败原因
echo $mysqli->connect_errno ;
}
//输入和输出都已经是UTF8了,中间编写的东西还给转码下,加上这句
$mysqli ->query("SET NAMES UTF8");
//var_dump($mysqli);
// //执行sql的查询语句,DESC是id倒叙
$sql = "SELECT * FROM admin ";
$mysqli_result = $mysqli->query( $sql ) ;
// if ($mysqli_result ===false) {
// echo "SQL错误";
// var_dump($mysqli_result);}
$row = $mysqli_result->fetch_array (MYSQLI_ASSOC);
var_dump($row);
//do和check
// if (isset($_GET['do'])&&$_GET['do']=='check'){
$auser = $_POST['auser'];
$apass = $_POST['apass'];
var_dump($auser, $apass);
// }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>管理员登录</title>
<link rel="stylesheet" href="../bootstrap3.3.7/css/bootstrap.css"/>
<script src="../bootstrap3.3.7/js/bootstrap.js"></script>
</head>
<body>
<div class="container">
<div class="row" style="margin-top: 200px">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">管理员登录</div>
<div class="panel-body">
<form class="form-horizontal"action="login.php?do=check" method="post" >
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">用户</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="auser" id="auser" placeholder="请输入用户名">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">密码</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="apass" id="apass" placeholder="请输入密码">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> 记住用户
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10 text-right ">
<button type="submit" class="btn btn-primary">提交登录</button>
</div>
</div>
</form>
</div>
<div class="panel-footer text-right" >zy的版权  </div>
</div>
</div>
<div class="col-md-3"></div>
</div>
</div>
</body>
</html>
|