<!-- 功能描述:有2个或多个字段的用户登录表单,点击按钮后提交到后端PHP,判断是否登陆成功。 Tips:尝试使用HTML编写一个Form表单,使用POST或GET方式提交。后端PHP接受提交的内容,然后去数据库查询。 Tips:尝试修复SQL注入漏洞 --> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>用户等入></title> </head> <body> <h2>PHP 表单验证实例</h2> <form method="post" action="index.php" method="post"> username: <input type="text" name="name"> <br><br> password: <input type="password" name="password"> <br><br> <input type="submit" name="submit" value="Submit"> </form> </body>
?php $name = $password = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = test_input($_POST["name"]); $password = test_input($_POST["password"]); $con = mysqli_connect("127.0.0.1","root","123456","admin"); if(!$con) { die("Connection failed: " . mysqli_connect_error()); } $sql="select * from admin where user='$name' and password='$password' "; $result =mysqli_query($con,$sql); $row = mysqli_fetch_array($result); if( $row >0 ){ echo "登入成功"; }else{ echo "登入失败"; } mysqli_close($con); } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>
打赏我,让我更有动力~
© 2016 - 2024 掌控者 All Rights Reserved.
Track-方丈
发表于 2018-6-29
通过
评论列表
加载数据中...