php(ex02b.php)
<?php
if(isset($_GET['name'])&&isset($_GET['sex'])){
$ID = $_GET['name'];
$sex = $_GET['sex'];
}
if(isset($_POST['name'])&&isset($_POST['sex'])&&isset($_POST['hobby'])&&isset($_POST['area'])&&isset($_POST['ect'])){
$ID = $_POST['name'];
$sex = $_POST['sex'];
$hobby = $_POST['hobby'];
$area = $_POST['area'];
$ect = $_POST['ect'];
echo $_GET['act'].'++++';
$conn=mysqli_connect("localhost","root","123","text3") or die("数据库连接失败");
mysqli_query($conn,'set names utf8');
$sql2="insert into student (id,sex,hobby,area,ect) VALUES ('$ID','$sex','$hobby','$area','$ect')";
if ($conn->query($sql2) === TRUE) {
} else {
echo "Error: " . $sql2. "<br>" . $conn->error;
}
$conn->close();
}
?>
<h1><?php if($sex=='女'){echo $ID.'女士';}else{echo $ID.'先生';}?>,您好,对不起,没有找到您的个人资料请填写您的详细信息!</h1>
<div style="position: absolute;height: 60%; 70%;left: 20%;top: 15%">
<form action="ex02b.php" method="post">
<table border="1" style="height: 100%; 100%">
<tr>
<td style="text-align: center" colspan="3">
学生个人信息
</td>
</tr>
<tr>
<td>您的姓名:</td>
<td colspan="2"><input name="name" type="text"></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="radio" name="sex" value="男">男<input type="radio" name="sex" value="女">女</td>
</tr>
<tr>
<td>年龄:</td>
<td colspan="2"><input name="hobby" type="text"></td>
</tr>
<tr>
<td>家庭住址:</td>
<td colspan="2">
<input name="area" type="text">
</td>
</tr>
<tr>
<td>
特长爱好:
</td>
<td colspan="2">
<input name="hobby" type="text">
</td>
</tr>
<tr>
<td colspan="3" style="text-align: center">
<input type="submit" value="提交"> <a href="ex02a.php">返回首页</a>
</td>
</tr>
</table>
</form>
</div>