这是php连接代码,html就不放了
<?php header("Content-Type:text/html; charset=utf-8"); //创建数据库链接:本地数据库,用户名:root,密码:空,数据库名称:test。
$connect = mysqli_connect("localhost","root","root"); // 定义变量并设置为空值 $name = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{ $name = test_input($_POST["name"]);
$password = test_input($_POST["password"]); }
function test_input($data)
{
$data = trim($data); $data = stripslashes($data);
$data = htmlspecialchars($data); return $data; } $flags=0; //从表admin中查询
$result = mysqli_query($connect,"SELECT * FROM admin where name = '".$name."'");
while($row = mysqli_fetch_array($result))
{
if($row['password']==$password) {$flags=1;} }
if($flags)
{
mysqli_query($connect,"UPDATE admin SET times = times+1 WHERE name = '".$name."'"); echo "alert(' 登 陆 成 功 ! ');window.location='html1.php';";//跳转回首页(index.php) } else
}
else
{
echo "alert(' 密 码 或 账 号 错 误 ! ');window.location='home.php';";//跳转回登录界面
}
mysqli_close($connect);?>