用PHP制作设计三个静态页面,分别为用户的注册页面、用户的登录页面、新添图书的插入页面;给出源代码
时间: 2024-03-09 14:49:37 浏览: 19
好的,以下是我用 PHP 制作的三个静态页面的源代码。这里我使用了 HTML、CSS 和 PHP 的组合。代码中包含注释,方便你了解每个部分的作用。
用户注册页面的代码:
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>注册页面</title>
<style>
/* CSS 样式表,用于美化页面 */
body {
font-family: Arial, sans-serif;
background-color: #f7f7f7;
}
form {
background-color: #fff;
border: 1px solid #ccc;
padding: 20px;
margin: 50px auto;
max-width: 400px;
box-shadow: 0px 0px 10px #ccc;
}
input[type="text"], input[type="password"], input[type="email"] {
display: block;
margin-bottom: 10px;
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 3px;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px;
border: none;
border-radius: 3px;
cursor: pointer;
}
</style>
</head>
<body>
<?php
// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
// 在此处添加注册用户的代码
echo '<p>注册成功!</p>';
} else {
// 显示注册表单
?>
<form method="post">
<h1>注册</h1>
<label>用户名:</label>
<input type="text" name="username" required>
<label>密码:</label>
<input type="password" name="password" required>
<label>确认密码:</label>
<input type="password" name="confirm_password" required>
<label>电子邮件地址:</label>
<input type="email" name="email" required>
<input type="submit" value="注册">
</form>
<?php
}
?>
</body>
</html>
```
用户登录页面的代码:
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录页面</title>
<style>
/* CSS 样式表,用于美化页面 */
body {
font-family: Arial, sans-serif;
background-color: #f7f7f7;
}
form {
background-color: #fff;
border: 1px solid #ccc;
padding: 20px;
margin: 50px auto;
max-width: 400px;
box-shadow: 0px 0px 10px #ccc;
}
input[type="text"], input[type="password"] {
display: block;
margin-bottom: 10px;
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 3px;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px;
border: none;
border-radius: 3px;
cursor: pointer;
}
</style>
</head>
<body>
<?php
// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
// 在此处添加验证用户名和密码的代码
if ($username == 'admin' && $password == '123456') {
echo '<p>登录成功!</p>';
} else {
echo '<p>用户名或密码错误!</p>';
}
} else {
// 显示登录表单
?>
<form method="post">
<h1>登录</h1>
<label>用户名:</label>
<input type="text" name="username" required>
<label>密码:</label>
<input type="password" name="password" required>
<input type="submit" value="登录">
</form>
<?php
}
?>
</body>
</html>
```
新添图书的插入页面的代码:
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>新添图书的插入页面</title>
<style>
/* CSS 样式表,用于美化页面 */
body {
font-family: Arial, sans-serif;
background-color: #f7f7f7;
}
form {
background-color: #fff;
border: 1px solid #ccc;
padding: 20px;
margin: 50px auto;
max-width: 400px;
box-shadow: 0px 0px 10px #ccc;
}
input[type="text"], input[type="file"] {
display: block;
margin-bottom: 10px;
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 3px;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px;
border: none;
border-radius: 3px;
cursor: pointer;
}
</style>
</head>
<body>
<?php
// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$author = $_POST['author'];
$publisher = $_POST['publisher'];
$isbn = $_POST['isbn'];
$image = $_FILES['image']['name'];
// 在此处添加插入图书的代码
echo '<p>插入成功!</p>';
} else {
// 显示插入表单
?>
<form method="post" enctype="multipart/form-data">
<h1>新添图书</h1>
<label>图书名称:</label>
<input type="text" name="name" required>
<label>作者:</label>
<input type="text" name="author" required>
<label>出版社:</label>
<input type="text" name="publisher" required>
<label>ISBN号:</label>
<input type="text" name="isbn" required>
<label>图书封面:</label>
<input type="file" name="image" required>
<input type="submit" value="插入">
</form>
<?php
}
?>
</body>
</html>
```
以上是我用 PHP 制作的三个静态页面的源代码,希望能对你有所帮助。注意,这里的代码只是一个参考,你需要根据自己的实际需求进行修改和完善。