PHP+MySQL 实现学生信息管理

一丶 实验要求

1、 按下列要求完成各个页面:(提示:在做此题前需先建立一数据库,包含一张表,此表至少包含 5 个字段(姓名,性别,兴趣爱好,家庭住址,备注))(1)制作静态页面 ex01a.php 如图 1 所示,当点击“提交”按钮时,可以向数据库中添加数据,如果添加数据失败,能给出提示,如果添加成功,则跳转到另一页面ex01b.php,如图 2 所示,本页面可以把数据库中所有的学生的资料显示出来。

 

图 1

 

图 2

(2) 当点击 ex01b.php 中的“修改”时,可将网页连接到 ex01c.php 如图 3 所示,可以修改学生的信息。该页面包含一个表单,每个表单控件的默认值均为ex01.php 页面中的学生的信息值。当点击“修改”按钮时,可以将该学生的信息进行修改,并保存到数据库中,成功保存数据后,可将页面转至 ex01b.php。

(3) 当点击“删除”时,如果能成功删除数据,则给出提示“数据删除成功!”,如图4所示,并将网页转至ex01b.php。数据删除失败也给出提示“数据删除失败!”。

图3

2、 按下列要求完成各个页面:(提示:此题的数据库中的表有 5 个字段(姓名,性别,年龄,家庭住址,特长爱好))

(1) 建立一个登陆页面 ex02a.php,如图 5

所示。 

(2) 如果你输入的个人资料(姓名和性别)在数据库中能够找到则将页面转到ex02c.php。

(3) 如果你输入个人资料在数据库中找不到,则在 ex02b.php 页面上半部分会给出提示“XXX 先生(小姐),您好,对不起,没有找到您的个人资料,请填写您的详细信息!”,其中“XXX”为你输入的姓名,当你输入的性别为“男”时则显示“先生”,当你输入的性别为“女”时则显示“小姐”,如图 6所示。

(4) 在 ex02b.php 页面的下半部分做一表单,如图 6 所示,包含“真实姓名”、“性别”、“年龄”、“家庭住址”、“特长爱好”等项目。

(5) 当点击保存按钮时,可以将你输入的信息保存到数据库中。如果保存成功则给出提示“您的资料保存成功!”,且能返回 ex02a.php 页面。

 

 

图 6

(6) 在 ex02c.php 页面中,在网页的上方插入一条红色水平线,在水平线上方书写文字:“您的个人资料如下:”,如图 7 所示。

(7) 在水平线下方建一表单,如图 7 所示,可以将你在 ex02a.php 网页中输入的这位同学的资料从数据库中调出并显示出来。

(8) 在表格的最下方建立“修改”和“删除”超链接,当点击“修改”时,可将网页连接到 ex02d.php 修改学生信息的页面,当点击“删除”时,如果能成功删除数据,则给出提示“数据删除成功!”,如图 8 所示,并将网页转至 ex02b.php。数据删除失败也给出提示“数据删除失败!”

 

图7

 

二丶 实现代码

01

1 <?php
2 $conn=mysqli_connect("127.0.0.1","root","101032","db_database01") or die("连接失败");
3 
4 mysqli_query($conn,'set names utf8'); //告诉服务器,本页面的字符集是utf8
5 
6 ?>
conn.php
 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title>添加个人资料</title>
 6     </head>
 7     <style>
 8         tr{
 9             text-align: center;
10         }
11     </style>
12     <body>
13         <form action="ex001a.php" method="post">
14             <table align="center" border="1" cellpadding="0" cellspacing="0" style="width: 600px;height: 400px;"> 
15                 <tr>
16                     <td colspan="2">
17                         <p>添加个人信息</p>
18                     </td>
19                     
20                 </tr>
21                 <tr>
22                     <td>真实姓名:</td>
23                     <td><input type="text" id="name" name="name"></td>
24                 </tr>
25                 <tr>
26                     <td>性别:</td>
27                     <td>
28                         <input type="radio" id="sex" name="sex" value="男" />29                         <input type="radio" id="sex" name="sex" value="女" />30                     </td>
31                 </tr>
32                 <tr>
33                     <td>兴趣爱好:</td>
34                     <td><input type="text" id="hobby" name="hobby"></td>
35                 </tr>
36                 <tr>
37                     <td>家庭住址:</td>
38                     <td>
39                         <select id="address" name="address">
40                             <option value="请选择您的住址">请选择您的住址 </option>
41                             <option value="石家庄">石家庄 </option>
42                             <option value="保定">保定 </option>
43                             <option value="秦皇岛">秦皇岛 </option>
44                         </select>                        
45                         
46                     </td>
47                 </tr>
48                 <tr>
49                     <td>备注:</td>
50                     <td><textarea id="beizhu" name="beizhu"  rows="4" cols="20"></textarea></td>
51                 </tr>
52                 <tr>
53                     <td colspan="2">
54                         <input type="submit" value="提交" />
55                         <input type="reset" value="重置" />
56                     </td>
57                 </tr>
58             </table>
59         </form>
60     </body>
61 </html>
62 
63 <?php
64 
65 ?>
ex01a.php
 1 <?php
 2 header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
 3 include_once('conn.php');
 4 
 5 $name=$_POST['name'];
 6 $sex=$_POST['sex'];
 7 $hobby=$_POST['hobby'];
 8 $address=$_POST['address'];
 9 $beizhu=$_POST['beizhu'];
10 
11 $sql = "insert into phpuser(name,sex,hobby,address,beizhu)values('{$name}','{$sex}','{$hobby}','{$address}','{$beizhu}')";
12 $result=mysqli_query($conn, $sql);
13 
14 if($result){
15     echo "<script>alert('添加成功');window.location.href='ex01b.php'</script>" ;
16 }else{
17     echo "<script>alert('添加失败');history.go(-1);</script>";
18 }
19 ?>
ex001a.php
 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title>个人信息</title>
 6     </head>
 7     <style>
 8         tr{
 9             text-align: center;
10         }
11     </style>
12     <body>
13         <table border="1" cellpadding="5" cellspacing="0" ">
14             <tr>
15                 <td colspan="7"><p>学生个人信息表 </p></td>
16             </tr>
17             <tr>
18                 <td>序号</td>
19                 <td>姓名</td>
20                 <td>性别</td>
21                 <td>爱好</td>
22                 <td>住址</td>
23                 <td>备注</td>
24                 <td colspan="2">操作</td>
25             </tr>
26             <tr>
27 <?php
28 include_once('conn.php');
29 
30     $sqlstr = "select * from phpuser";
31     $result = mysqli_query($conn,$sqlstr);
32     
33     while ($rows = mysqli_fetch_row($result)){
34         echo "<tr>";
35         for($i = 0; $i < count($rows); $i++){
36             echo "<td >".$rows[$i]."</td>";
37         }
38         echo "<td><a href='ex01b_update.php?id={$rows[0]}&name={$rows[1]}&sex={$rows[2]}&hobby={$rows[3]}&address={$rows[4]}&beizhu={$rows[5]}'>修改</a>/<a href='ex01b_delete.php?id={$rows[0]}'>删除</a></td>";
39         echo "</tr>";
40     }
41 
42 
43 ?>    
44             </tr>
45         </table>
46     </body>
47 </html>
48 
49 
50 <?php
51 
52 ?>
ex01b.php
 1 <?php
 2 header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
 3 include_once('conn.php');
 4 $id=$_GET['id'];
 5 
 6     $sqlstr1 = "delete from phpuser where id = '{$id}'";        //定义删除语句
 7     $result = mysqli_query($conn,$sqlstr1);                //执行删除操作
 8     if($result){
 9         echo "<script>alert('删除成功');history.go(-1);</script>";
10     }else{
11         echo "<script>alert('删除失败');history.go(-1);</script>";
12     }
13 ?>
ex01b_delete.php
  1 <?php
  2 header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
  3 include_once('conn.php');
  4 $id=$_GET['id'];
  5 $name=$_GET['name'];
  6 $sex=$_GET['sex'];
  7 $hobby=$_GET['hobby'];
  8 $address=$_GET['address'];
  9 $beizhu=$_GET['beizhu'];
 10 
 11 ?>
 12 
 13 
 14 <!DOCTYPE html>
 15 <html>
 16     <head>
 17         <meta charset="UTF-8">
 18         <title>修改个人资料</title>
 19     </head>
 20     <style>
 21         tr{
 22             text-align: center;
 23         }
 24     </style>
 25     <body>
 26         <form action="ex01b_update_sql.php" method="post">
 27             <table align="center" border="1" cellpadding="0" cellspacing="0" style="width: 600px;height: 400px;"> 
 28                 <tr>
 29                     <td colspan="2">
 30                         <p>修改个人信息</p>
 31                     </td>
 32                     
 33                 </tr>
 34                 <tr>
 35                     <td>序号:</td>
 36                     <td><input type="text" id="id" name="id" readonly="readonly" value="<?php echo $id; ?>" ></td>
 37                 </tr>
 38                 <tr>
 39                     <td>真实姓名:</td>
 40                     <td><input type="text" id="name" name="name" value="<?php echo $name; ?>"></td>
 41                 </tr>
 42                 <tr>
 43                     <td>性别:</td>
 44                     <td>
 45                         <?php 
 46                         
 47                         if (strcmp($sex,"男")==0){
 48                             
 49                             echo "<input type='radio' id='sex' name='sex' value='男' checked='checked'/>男<input type='radio' id='sex' name='sex' value='女' />女";
 50                             
 51                         }else{
 52                             echo "<input type='radio' id='sex' name='sex' value='男' />男<input type='radio' id='sex' name='sex' value='女' checked='checked'/>女";
 53                         }
 54                             
 55                         ?>
 56                         
 57                         
 58                     </td>
 59                 </tr>
 60                 <tr>
 61                     <td>兴趣爱好:</td>
 62                     <td><input type="text" id="hobby" name="hobby" value="<?php echo $hobby; ?>"></td>
 63                 </tr>
 64                 <tr>
 65                     <td>家庭住址:</td>
 66                     <td>
 67                         <select id="address" name="address">
 68                             
 69                             <?php
 70                                 
 71                             if(strcmp($address,"保定")==0)    {
 72                                 
 73                                 echo "<option value='保定'>保定 </option><option value='石家庄' >石家庄 </option><option value='秦皇岛'>秦皇岛 </option>";
 74                                 
 75                             }else if(strcmp($address,"石家庄")==0){
 76                                 echo "<option value='石家庄' >石家庄 </option><option value='保定'>保定 </option><option value='秦皇岛'>秦皇岛 </option>";
 77                             }else{
 78                                 echo "<option value='秦皇岛'>秦皇岛 </option><option value='石家庄' >石家庄 </option><option value='保定'>保定 </option>";
 79                             }
 80                                 
 81                                 
 82                             ?>
 83                             
 84                             
 85                         </select>                        
 86                         
 87                     </td>
 88                 </tr>
 89                 <tr>
 90                     <td>备注:</td>
 91                     <td><textarea id="beizhu" name="beizhu"  rows="4" cols="20" ><?php echo $beizhu; ?></textarea></td>
 92                 </tr>
 93                 <tr>
 94                     <td colspan="2">
 95                         <input type="submit" value="提交" />
 96                         <input type="reset" value="重置" />
 97                     </td>
 98                 </tr>
 99             </table>
100         </form>
101     </body>
102 </html>
103 
104 <?php
105 
106 ?>
ex01b_update.php
 1 <?php
 2 header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
 3 include_once('conn.php');
 4 
 5 $id=$_POST['id'];
 6 $name=$_POST['name'];
 7 $sex=$_POST['sex'];
 8 $hobby=$_POST['hobby'];
 9 $address=$_POST['address'];
10 $beizhu=$_POST['beizhu'];
11 
12 $sql = "update phpuser set name='{$name}',sex='{$sex}',hobby='{$hobby}',address='{$address}',beizhu='{$beizhu}' where id='{$id}'";
13 $result=mysqli_query($conn, $sql);
14 
15 if($result){
16     echo "<script>alert('更新成功');window.location.href='ex01b.php';</script>" ;
17 }else{
18     echo "<script>alert('更新失败');history.go(-1);</script>";
19 }
20 ?>
ex01b_update_sql.php

02

1 <?php
2 $conn=mysqli_connect("127.0.0.1","root","101032","db_database01") or die("连接失败");
3 
4 mysqli_query($conn,'set names utf8'); //告诉服务器,本页面的字符集是utf8
5 
6 ?>
conn.php
 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title>login</title>
 6     </head>
 7     <style>
 8         tr{
 9             text-align: center;
10         }
11     </style>
12     <body>
13         <form action="ex02a.php" method="post">
14             <table border="1" cellpadding="5" cellspacing="0">
15                 <tr>
16                     <td colspan="2">
17                         <h1>用户登陆</h1>
18                     </td>
19                     
20                 </tr>
21                 <tr>
22                     <td>姓名:</td>
23                     <td><input type="text" id="name" name="name"></td>
24                 </tr>
25                 <tr>
26                     <td>性别:</td>
27                     <td>
28                         <input type="radio" value="男" id="sex" name="sex">29                         <input type="radio" value="女" id="sex" name="sex">30                     </td>
31                 </tr>
32                 <tr>
33                     <td colspan="2">
34                         <input type="submit" value="提交" />
35                     </td>
36                 </tr>
37             </table>
38         </form>
39     </body>
40 </html>
41 
42 <?php
43 
44 header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
45 include_once('conn.php');
46 
47 
48 
49 if($_POST){
50 $name=$_POST['name'];
51 $sex=$_POST['sex'];
52 
53 
54 if($name!=""&&$sex!=""){
55     $sqlstr = "select * from php_user_02 where name='{$name}' and sex='{$sex}'";
56     $result = mysqli_query($conn,$sqlstr);
57     $line=mysqli_num_rows($result);
58     
59     if($line==1){
60         $rows = mysqli_fetch_row($result);
61         $id=$rows[0];
62         echo "<script>alert('登陆成功');window.location.href='ex02c.php?id={$id}'</script>" ;
63     }else{
64         echo "<script>alert('登陆失败');window.location.href='ex02b.php?name={$name}&sex={$sex}'</script>" ;
65     }    
66 }else{
67     echo "<script>alert('请完整填写信息');history.go(-1);</script>";
68         
69 }
70 
71 }
72 ?>
ex02a.php
 1 <?php 
 2     
 3     header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
 4     include_once('conn.php');
 5     
 6     if(is_array($_POST)&&count($_POST)>0){
 7     if(isset($_POST["name"])&isset($_POST["sex"])&isset($_POST["age"])&isset($_POST["address"])&isset($_POST["hobby"])){
 8         $name=$_POST['name'];
 9         $sex=$_POST['sex'];
10         $age=$_POST['age'];
11         $address=$_POST['address'];
12         $hobby=$_POST['hobby'];
13         
14         $sql = "insert into php_user_02(name,sex,age,address,hobby)values('{$name}','{$sex}','{$age}','{$address}','{$hobby}')";
15         $result=mysqli_query($conn, $sql);
16         if($result){
17             echo "<script>alert('您的资料保存成功!');window.location.href='ex02a.php'</script>" ;
18         }else{
19             echo "<script>alert('请将所有信息填写完整!');history.go(-1);</script>";
20         }
21         
22 }
23     
24 }
25     
26 ?>
ex02a_save.php
 1 <?php
 2 header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
 3 include_once('conn.php');
 4 
 5 
 6 
 7 
 8 if(is_array($_GET)&&count($_GET)>0)//先判断是否通过get传值了
 9     {
10         if(isset($_GET["name"])&isset($_GET["sex"]))
11         {
12             $name=$_GET['name'];
13             $sex=$_GET['sex'];
14             if (strcmp($sex,"男" )==0){
15                 echo "<h4 align='center' style='color: green;'>$name  先生您好, 没有找到您的个人资料,请填写您的详细信息!</h4>";
16             }else{
17                 echo "<h4 align='center' style='color: green;'>$name  小姐您好, 没有找到您的个人资料,请填写您的详细信息!</h4>";
18             }
19         }
20     }
21 echo "<hr color='red'>";
22 ?>
23 
24 <!DOCTYPE html>
25 <html>
26     <head>
27         <meta charset="UTF-8">
28         <title>添加个人资料</title>
29     </head>
30     <style>
31         tr{
32             text-align: center;
33         }
34     </style>
35     <body>
36         
37         <form action="ex02b_save.php" method="post">
38             <table align="center" border="1" cellpadding="0" cellspacing="0" style="width: 600px;height: 400px;"> 
39                 <tr>
40                     <td colspan="2">
41                         <p>添加个人信息</p>
42                     </td>
43                     
44                 </tr>
45                 <tr>
46                     <td>真实姓名:</td>
47                     <td><input type="text" id="name" name="name"></td>
48                 </tr>
49                 <tr>
50                     <td>性别:</td>
51                     <td>
52                         <input type="radio" id="sex" name="sex" value="男" />53                         <input type="radio" id="sex" name="sex" value="女" />54                     </td>
55                 </tr>
56                 <tr>
57                     <td>年龄:</td>
58                     <td><input type="radio" id="age" name="age" value="17" />17岁
59                         <input type="radio" id="age" name="age" value="18" />18岁
60                         <input type="radio" id="age" name="age" value="19" />19岁
61                         <input type="radio" id="age" name="age" value="20" />20岁
62                     
63                     </td>
64                 </tr>
65                 <tr>
66                     <td>家庭住址:</td>
67                     <td>
68                         <select id="address" name="address">
69                             <option value="请选择您的住址">请选择您的住址 </option>
70                             <option value="石家庄">石家庄 </option>
71                             <option value="保定">保定 </option>
72                             <option value="秦皇岛">秦皇岛 </option>
73                         </select>                        
74                         
75                     </td>
76                 </tr>
77                 <tr>
78                     <td>特长爱好:</td>
79                     <td><textarea id="hobby" name="hobby"  rows="4" cols="20"></textarea></td>
80                 </tr>
81                 <tr>
82                     <td colspan="2">
83                         <input type="submit" value="提交" />
84                         <input type="reset" value="重置" />
85                     </td>
86                 </tr>
87             </table>
88         </form>
89     </body>
90 </html>
ex02b.php
 1 <?php
 2 
 3 header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
 4 include_once('conn.php');
 5 
 6 $id=$_GET['id'];
 7 $sqlstr = "select * from php_user_02 where id='{$id}'";
 8 $result = mysqli_query($conn,$sqlstr);
 9 $rows = mysqli_fetch_row($result);
10 
11 $name=$rows[1];
12 $sex=$rows[2];
13 $age=$rows[3];
14 $address=$rows[4];
15 $hobby=$rows[5];
16 
17 
18 echo "<h4 align='center' style='color: green;'> 您的个人资料如下:</h4>";
19 echo "<hr color='red'>";
20 ?>
21 
22 
23 <!DOCTYPE html>
24 <html>
25     <head>
26         <meta charset="UTF-8">
27         <title>个人资料</title>
28     </head>
29     <style>
30         tr{
31             text-align: center;
32         }
33     </style>
34     <body>
35         
36         <form action="" method="post">
37             <table align="center" border="1" cellpadding="0" cellspacing="0" style="width: 600px;height: 400px;"> 
38                 <tr>
39                     <td colspan="2">
40                         <p>学生个人信息表</p>
41                     </td>
42                 </tr>
43                 <tr>
44                     <td>真实姓名:</td>
45                     <td>
46                         <?php echo $name; ?>
47                     </td>
48                 </tr>
49                 <tr>
50                     <td>性别:</td>
51                     <td>
52                         <?php echo $sex; ?>
53                     </td>
54                 </tr>
55                 <tr>
56                     <td>年龄:</td>
57                     <td>
58                     <?php echo $age; ?>
59                     </td>
60                 </tr>
61                 <tr>
62                     <td>家庭住址:</td>
63                     <td>
64                             <?php echo $address; ?>
65                     </td>
66                 </tr>
67                 <tr>
68                     <td>特长爱好:</td>
69                     <td>
70                         <?php echo $hobby; ?>
71                     </td>
72                 </tr>
73                 <tr>
74                     <td colspan="2">
75                         <?php
76                         echo "<a href='ex02d.php?id={$rows[0]}&id={$rows[0]}&name={$rows[1]}&sex={$rows[2]}&age={$rows[3]}&address={$rows[4]}&hobby={$rows[5]}'>修改     </a>";    
77                         echo "<a href='ex02c_delete.php?id={$rows[0]}'>   删除</a>";
78                         ?>
79                     </td>
80                 </tr>
81                 <tr>
82                     <td colspan="2">
83                         <a href="ex02a.php">返回首页!</a>
84                     </td>
85                 </tr>
86             </table>
87         </form>
88     </body>
89 </html>
ex02c.php
 1 <?php
 2 
 3 header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
 4 include_once('conn.php');
 5 
 6 $id=$_GET['id'];
 7 echo $id;
 8 
 9 $sqlstr1 = "delete from php_user_02 where id = '{$id}'";        //定义删除语句
10 $result = mysqli_query($conn,$sqlstr1);                //执行删除操作
11 if($result){
12     echo "<script>alert('数据删除成功!');window.location.href='ex02a.php'</script>";
13 }else{
14     echo "<script>alert('删除失败');history.go(-1);</script>";
15 }
16 
17 
18 ?>
ex02c_delete.php
  1 <?php
  2     header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
  3     include_once('conn.php');
  4     
  5     $id=$_GET['id'];
  6     $name=$_GET['name'];
  7     $sex=$_GET['sex'];
  8     $hobby=$_GET['hobby'];
  9     $age=$_GET['age'];
 10     $address=$_GET['address'];
 11     
 12 
 13 ?>
 14 
 15 
 16 
 17 <!DOCTYPE html>
 18 <html>
 19     <head>
 20         <meta charset="UTF-8">
 21         <title>修改个人资料</title>
 22     </head>
 23     <style>
 24         tr{
 25             text-align: center;
 26         }
 27     </style>
 28     <body>
 29         
 30         <form action="ex02d_update.php" method="post">
 31             <table align="center" border="1" cellpadding="0" cellspacing="0" style="width: 600px;height: 400px;"> 
 32                 <tr>
 33                     <td colspan="2">
 34                         <p>修改个人信息</p>
 35                     </td>
 36                     
 37                 </tr>
 38                 <tr>
 39                     <td>序号:</td>
 40                     <td><input type="text" id="id" name="id"  readonly="readonly" value="<?php echo $id;?>" ></td>
 41                 </tr>
 42                 <tr>
 43                     <td>真实姓名:</td>
 44                     <td><input type="text" id="name" name="name" value="<?php echo $name;?>"></td>
 45                 </tr>
 46                 <tr>
 47                     <td>性别:</td>
 48                     <td>
 49                         
 50                         <?php 
 51                         
 52                         if (strcmp($sex,"男")==0){
 53                             
 54                             echo "<input type='radio' id='sex' name='sex' value='男' checked='checked'/>男<input type='radio' id='sex' name='sex' value='女' />女";
 55                             
 56                         }else{
 57                             echo "<input type='radio' id='sex' name='sex' value='男' />男<input type='radio' id='sex' name='sex' value='女' checked='checked'/>女";
 58                         }
 59                             
 60                         ?>
 61                     </td>
 62                 </tr>
 63                 <tr>
 64                     <td>年龄:</td>
 65                     <td>
 66                         
 67                         <?php
 68                             
 69                             if ($age==17){
 70                                     
 71                                 echo "<input type='radio' id='age' name='age' value='17' checked='checked' />17岁<input type='radio' id='age' name='age' value='18' />18岁<input type='radio' id='age' name='age' value='19' />19岁<input type='radio' id='age' name='age' value='20' />20岁" ;
 72                                 
 73                             }else if($age==18){
 74                 
 75                                 echo "<input type='radio' id='age' name='age' value='17'  />17岁<input type='radio' id='age' name='age' value='18' checked='checked'/>18岁<input type='radio' id='age' name='age' value='19' />19岁<input type='radio' id='age' name='age' value='20' />20岁" ;    
 76                             }else if($age==19){
 77                                 echo "<input type='radio' id='age' name='age' value='17'  />17岁<input type='radio' id='age' name='age' value='18' />18岁<input type='radio' id='age' name='age' value='19' checked='checked'/>19岁<input type='radio' id='age' name='age' value='20' />20岁" ;    
 78                             }else{
 79                                 echo "<input type='radio' id='age' name='age' value='17'  />17岁<input type='radio' id='age' name='age' value='18' />18岁<input type='radio' id='age' name='age' value='19' />19岁<input type='radio' id='age' name='age' value='20' checked='checked'/>20岁" ;    
 80                             }
 81                             ?>
 82                     
 83                     </td>
 84                 </tr>
 85                 <tr>
 86                     <td>家庭住址:</td>
 87                     <td>
 88                         <select id="address" name="address">
 89                             
 90                             <?php
 91                                 
 92                             if(strcmp($address,"保定")==0)    {
 93                                 
 94                                 echo "<option value='保定'>保定 </option><option value='石家庄' >石家庄 </option><option value='秦皇岛'>秦皇岛 </option>";
 95                                 
 96                             }else if(strcmp($address,"石家庄")==0){
 97                                 echo "<option value='石家庄' >石家庄 </option><option value='保定'>保定 </option><option value='秦皇岛'>秦皇岛 </option>";
 98                             }else{
 99                                 echo "<option value='秦皇岛'>秦皇岛 </option><option value='石家庄' >石家庄 </option><option value='保定'>保定 </option>";
100                             }
101                                 
102                                 
103                             ?>
104                         </select>                        
105                         
106                     </td>
107                 </tr>
108                 <tr>
109                     <td>特长爱好:</td>
110                     <td><textarea id="hobby" name="hobby"  rows="4" cols="20"><?php echo $hobby;?></textarea></td>
111                 </tr>
112                 <tr>
113                     <td colspan="2">
114                         <input type="submit" value="修改" />
115                     </td>
116                 </tr>
117             </table>
118         </form>
119     </body>
120 </html>
ex02d.php
 1 <?php
 2 
 3 header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
 4 include_once('conn.php');
 5 
 6 $id=$_POST['id'];
 7 $name=$_POST['name'];
 8 $sex=$_POST['sex'];
 9 $hobby=$_POST['hobby'];
10 $address=$_POST['address'];
11 $age=$_POST['age'];
12 
13 $sql = "update php_user_02 set name='{$name}',sex='{$sex}',age='{$age}',address='{$address}',hobby='{$hobby}' where id='{$id}'";
14 $result=mysqli_query($conn, $sql);
15 
16 if($result){
17     echo "<script>alert('修改成功');window.location.href='ex02a.php';</script>" ;
18 }else{
19     echo "<script>alert('更新失败');history.go(-1);</script>";
20 }
21 
22 
23 
24 ?>
ex02d_update.php

 

猜你喜欢

转载自www.cnblogs.com/cxy0210/p/12976982.html