用HTML+CSS+JS设计三个页面
Login.html/Success.html/Failed.html,使用js检测登陆的用户名和密码是否正确,根据正确与否可以跳转到Success.html或Faile...
Login.html/Success.html/Failed.html,使用js检测登陆的用户名和密码是否正确,根据正确与否可以跳转到Success.html或Failed.html页面。使用css可以同时改变三个页面的网页风格。
展开
2个回答
展开全部
用PHP做过一个,你照着这个换成JS的就可以了:
下面为login.php:
<?php
session_start();
unset($_SESSION['name']);
mysql_connect("localhost", "root" ,"Changsha01") or die("Could not connect");
mysql_select_db("test") or die("Could not use db");
if (isset($_POST['submit'])) {
$name = trim($_POST['name']);
$password = trim($_POST['password']);
if (empty($name) || empty($password)) {
$flag = true;
}else {
$query = "SELECT password FROM users WHERE login_name = '" . $name . "'";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if ($password == $row['password']) {
$_SESSION['name'] = $name;
header("location: index.php");
} else {
$flag = true;
}
}
}
?>
<html>
<head><title>my document</title></head>
<body>
<form action="login.php" method=post>
<table align="center" border="0" style="padding-top:300px" >
<tr>
<td align="right">Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="password"></td>
</tr>
<?php
if (isset($flag)) {
?>
<tr>
<td colspan="2"><font color="red">Wrong Login or Password</font></td>
</tr>
<?php
}
?>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="submit"> <input type="reset" value="clear" ></td>
</tr>
</table>
</form>
</body>
</html>
下面为Success.html:
<html>
<head><title>Sucess</title></head>
<body>
<b>Sucess</b>
</body>
</head>
下面为Failed.html:
<html>
<head><title>Sucess!</title></head>
<body>
<b>Failed!</b>
</body>
</head>
下面为login.php:
<?php
session_start();
unset($_SESSION['name']);
mysql_connect("localhost", "root" ,"Changsha01") or die("Could not connect");
mysql_select_db("test") or die("Could not use db");
if (isset($_POST['submit'])) {
$name = trim($_POST['name']);
$password = trim($_POST['password']);
if (empty($name) || empty($password)) {
$flag = true;
}else {
$query = "SELECT password FROM users WHERE login_name = '" . $name . "'";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if ($password == $row['password']) {
$_SESSION['name'] = $name;
header("location: index.php");
} else {
$flag = true;
}
}
}
?>
<html>
<head><title>my document</title></head>
<body>
<form action="login.php" method=post>
<table align="center" border="0" style="padding-top:300px" >
<tr>
<td align="right">Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="password"></td>
</tr>
<?php
if (isset($flag)) {
?>
<tr>
<td colspan="2"><font color="red">Wrong Login or Password</font></td>
</tr>
<?php
}
?>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="submit"> <input type="reset" value="clear" ></td>
</tr>
</table>
</form>
</body>
</html>
下面为Success.html:
<html>
<head><title>Sucess</title></head>
<body>
<b>Sucess</b>
</body>
</head>
下面为Failed.html:
<html>
<head><title>Sucess!</title></head>
<body>
<b>Failed!</b>
</body>
</head>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询