1
0
Fork 0
php-coding/8.work1_4.php

131 lines
4.4 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户注册</title>
</head>
<body>
<form method="post" action="#" enctype="multipart/form-data">
<table>
<tr>
<th colspan="2" style="text-align: center">
<h1>用户注册</h1>
</th>
</tr>
<tr>
<td>
<label for="name1">姓名:</label>
</td>
<td>
<input type="text" name="name" id="name1" required>
</td>
</tr>
<tr>
<td>
<label>性别:</label>
</td>
<td>
<input type="radio" name="sex" value="" id="sex1">
<label for="sex1"></label>
<input type="radio" name="sex" value="" id="sex2">
<label for="sex2"></label>
</td>
</tr>
<tr>
<td>
<label for="password1">密码:</label>
</td>
<td>
<input type="password" name="password" id="password1" required>
</td>
</tr>
<tr>
<td>
<label for="education1">学历:</label>
</td>
<td>
<select name="education" size="1" id="education1">
<option value="初中">初中</option>
<option value="高中">高中</option>
<option value="大学">大学</option>
<option value="硕士">硕士</option>
<option value="博士">博士</option>
</select>
</td>
</tr>
<tr>
<td>
<label>爱好:</label>
</td>
<td>
<input type="checkbox" name="hobby[]" id="hobby1" value="电脑">
<label for="hobby1">电脑</label>
<input type="checkbox" name="hobby[]" id="hobby2" value="音乐">
<label for="hobby2">音乐</label>
<input type="checkbox" name="hobby[]" id="hobby3" value="旅游">
<label for="hobby3">旅游</label>
<input type="checkbox" name="hobby[]" id="hobby4" value="其他">
<label for="hobby4">其他</label>
</td>
</tr>
<tr>
<td>
<label for="photo1">头像:</label>
</td>
<td>
<input type="file" size="5" accept=".jpg, .jpeg, .png, .gif" id="photo1" name="photo" required>
</td>
</tr>
<tr>
<td>
<label for="note1">个人简介:</label>
</td>
<td>
<textarea name="note" id="note1" wrap="hard"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<input type="submit" name="submit" value="提交">
<input type="reset" name="reset" value="重置">
</td>
</tr>
</table>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['submit']) && $_POST['submit'] != '') {
echo '###提交的信息如下###<br>';
echo '姓名:' . $_POST['name'] . '<br>';
echo '性别:' . $_POST['sex'] . '<br>';
echo '密码:' . $_POST['password'] . '<br>';
if (isset($_POST['education']) && $_POST['education'] != '') {
echo '学历:' . $_POST['education'] . '<br>';
}
if (isset($_POST['hobby']) && count($_POST['hobby']) != 0) {
echo '爱好:';
foreach ($_POST['hobby'] as $item) {
echo $item . ' ';
}
echo '<br>';
}
if ($_FILES["photo"]["error"] > 0) {
echo "Error: " . $_FILES["photo"]["error"];
} else {
$file_org = $_FILES["photo"]["tmp_name"];
$file_target = 'images/' . basename($_FILES["photo"]["name"]);
if (move_uploaded_file($file_org, $file_target)) {
echo '头像:' . '<img style="max-width: 100px; max-height: 100px;" alt="person photo" src="' . $file_target . '"><br>';
} else {
echo "头像上传失败。";
}
}
if (isset($_POST['note']) && $_POST['note'] != '') {
echo '个人介绍:' . nl2br($_POST['note']) . '<br>';
}
}
}
?>
</body>