a1174650302
绒布a
2017-12-19 12:09

为什么PHP验证登录后台验证不成功

5
  • php
  • 数据库

这是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(&#39; 登 陆 成 功 ! &#39;);window.location=&#39;html1.php&#39;;";//跳转回首页(index.php) } else
}
else
{

echo "alert(&#39; 密 码 或 账 号 错 误 ! &#39;);window.location=&#39;home.php&#39;;";//跳转回登录界面
}
mysqli_close($connect);?>

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

11条回答