题目要求:
登录页面:设计一个登录页面,获取登录表单中的用户名和密码,如果用户名为“admin”,密码为“123456”,则提示登录成功。效果参考下图:
代码:
1.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>表单</title>
<style>
.a{
display: flex;
flex-direction: column;
align-items: center;
}
table {
border:1px solid #000000;
text-align: center;
}
table th{
background-color: darkgray;
border:1px solid #000000;
}
table td{
border:1px solid #000000;
text-align: center;
} </style>
</head>
<body>
<div class="a">
<form action="page2.php" method="post">
<table>
<tr><th colspan="2">用户登录表单</th></tr>
<tr>
<td>用户名:</td>
<td><input type="text" name="a" required></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="b" required></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="登录"/><input type="reset" name=“Reset”></td>
</tr>
</table>
</from>
</div>
</body>
</html>
page2.php
<?php
$username=$_POST["a"];
$password=$_POST["b"];
if(strcmp($username,"admin")==0 && strcmp($password,"123456" )==0)
{ echo"<script>";
echo"alert('登录成功');";
echo"</script>";
}else{
echo"<script>";
echo"alert('账号或密码错误');";
echo "location.href='1.php';";
echo"</script>";
}
?>
成果图:
发表评论 取消回复