gpt4 book ai didi

php - 需要检查MySQL数据库并在验证后登录

转载 作者:搜寻专家 更新时间:2023-10-30 23:09:05 27 4
gpt4 key购买 nike

我需要得到管理员名称和密码,然后需要比较用户输入和使用php的mysql。如果数据库有效,我应该让他登录到下一页。如何编写php函数来访问mysql,在检查数据库验证是否正常之后。我应该登录他。
我的HTML设计代码:

  <?php

?>
<!DOCTYPE HTML>

<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
<script src="js/home.js"> </script>
</head>
<body>
<form action="validate_login.php" method="post">
<div>
<div class="layout">
<div class="heading"></div>
<div class="img1"></div>
<div class="login">
<div class="logo"></div>
<div > <label class="AdminName">Admin Name</label> <input type="text" name="AdminName" value="AdminName" id="AdminName"/></div>
<div > <label class="Password">Password</label> <input type="password" name="Password" value="Password" id="Password" /></div>
<input type="button" button onclick='window.location="menu.php"' name="Login" id="login" value="LOGIN"/>
<input type="button" name="Login" id="cancel" value="cancel"/></form>
</div>
<div class="img2"></div>
</div>

</div>
</body>

我访问数据库的php代码:
 <?php

// Grab User submitted information
$AdminName = $_POST["AdminName"];
$Password = $_POST["Password"];

// Connect to the database
$con = mysql_connect("localhost","admin","admin@123");
// Make sure we connected succesfully
if(! $con)
{
die('Connection Failed'.mysql_error());
}

// Select the database to use
mysql_select_db("admin_data",$con);

$result = mysql_query("SELECT AdminName, Password FROM admin_info WHERE AdminName = $AdminName");

$row = mysql_fetch_array($result);

if($row["AdminName"]==$AdminName && $row["Password"]==$Password)
echo"You are a validated user.";
else
echo"Sorry, your credentials are not valid, Please try again.";
?>

最佳答案

试一试

$result = mysql_query("SELECT AdminName, Password FROM admin_info WHERE AdminName = '".mysql_real_escape_string($AdminName)."' AND Password = '".mysql_real_escape_string($Password)."'");

关于php - 需要检查MySQL数据库并在验证后登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22395970/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com