index.html页面
<html> <head> <meta http-equiv="Content-Language" content="zh-cn"> <!--<meta http-equiv="Content-Type" content="text/html; charset=gb2312">--> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>input</title> </head> <body> <form method="POST" action="receive.php"> <p>您的姓名: <input type="text" name="T1" size="20"></p> <p>您的性别:男<input type="radio" value="0" name="R1"> 女<input type="radio" name="R1" value="1"></p> <p>您的EMAIL:<input type="text" name="T2" size="35"></p> <p>您的留言内容:</p> <p> <textarea rows="16" name="S1" cols="45"></textarea></p> <p> </p> <p> <input type="submit" value="提交" name="B1"> <input type="reset" value="重置" name="B2"></p> </form> </body> </html>
receive.php
<?php header("content-type:text/html;charset=utf-8"); $user='root'; $password='root'; $db='guestbook'; $table='gbook'; $connect=mysql_connect('localhost',$user,$password); if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } $T1=$_POST["T1"]; $R1=$_POST["R1"]; $T2=$_POST["T2"]; $S1=$_POST["S1"]; mysql_select_db("guestbook"); $sql = "INSERT INTO `guestbook`.`gbook` ( name, sex, email, info) VALUES ('$T1', '$R1', '$T2', '$S1')"; $result1=mysql_query( $sql); if( $result1) { //echo"数据插入成功"; $result=mysql_query("select * from $table "); $arr=mysql_fetch_array($result); while ($arr=mysql_fetch_array($result)) { if ($arr[1]==0) { $gender='先生'; $name=$arr[0]; $info=$arr[3]; $id=$arr[4]; } else { $gender='女人'; $name=$arr[0]; $info=$arr[3]; $id=$arr[4]; } } echo "<table border='1' width ='100%' align=center bgcolor='#FFFFF'> <tr> <td bordercolor='#FFFFFF' bgcolor='#C0C0C0'> <p>$name $gender 写到:</p> <tr> <td>    $info</td> </td> </tr> "; echo "</table>"; echo"<a href=\"del.php?id=$id\">[删除]</a> <a href=\"modify.php?id=$id\">[修改]</a>] "; } else { echo"数据插入失败"; } ?> <!--<html>--> <!-- <head>--> <!-- <meta http-equiv="Content-Language" content="zh-cn">--> <!-- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">--> <!-- <title>Receive</title>--> <!-- </head> --> <!--<body style="background-attachment: fixed">--> <!-- <table border="1" width="100%" id="table1" bgcolor="#FFFFFF"> --> <!--<tr> <td >--> <!-- <p><a href="del.php?id=$id">[删除]</a> --> <!-- <a href="modify.php?id=$id">[修改]</a>]--> <!-- </td> --> <!--</tr>--> <!-- </table> --> <!--</body> --> <!--</html> --> <?php echo '<p>'; echo '<p>'; ?> <html> <head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>返回</title> </head> <body> <p><a href="index.html"><继续留言></a></p> </body> </html>
del.php
<?php header("content-type:text/html;charset=utf-8");//防止中文乱码 $id=$_GET['id']; //echo $id; //exit;// $user='root'; $password='root'; $db='guestbook'; $table='gbook'; $sql="DELETE FROM $table WHERE id=$id"; $connect=mysql_connect('localhost',$user,$password); mysql_select_db($db); $result=mysql_query($sql); if ($result) echo "数据删除成功"; else echo "数据删除失败"; ?> <html> <head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>删除</title> </head> <body> <p><a href="index.html">继续留言</a></p> </body> </html>
modify.php修改
<?php header("content-type:text/html;charset=utf-8"); $id=$_GET['id']; $user='root'; $password='root'; $db='guestbook'; $table='gbook'; $connect=mysql_connect('localhost',$user,$password); mysql_select_db($db); $result=mysql_query("select * from $table where id=$id"); //if($result) //{ // echo"数据查询成功"; // exit; //} $arr=mysql_fetch_array($result); ?> <html> <head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>input</title> </head> <body> <form method="POST" action="modify_ok.php?id=<?=$id?>"> <p>您的姓名: <input type="text" name="T1" size="20" value="<?=$arr[0]?>"></p> <p>您的性别: <?php if ($arr[1]==0) echo '男<input type="radio" value="0" name="R1" checked> 女<input type="radio" name="R1" value="1"></p>'; else echo '男<input type="radio" value="0" name="R1"> 女<input type="radio" name="R1" value="1" checked></p>'; ?> <p>您的EMAIL:<input type="text" name="T2" size="35" value="<?=$arr[2]?>"></p> <p>您的留言内容:</p> <p> <textarea rows="16" name="S1" cols="45" ><?=$arr[3]?></textarea></p> <p> </p> <p> <input type="submit" value="修改" name="B1"> <input type="reset" value="重置" name="B2"></p> </form> </body> </html>
修改成功页面
modify_ok.php
<?php header("content-type:text/html;charset=utf-8"); $id=$_GET['id']; $user='root'; $password='root'; $db='guestbook'; $table='gbook'; $connect=mysql_connect('localhost',$user,$password); $T1=$_POST["T1"]; $R1=$_POST["R1"]; $T2=$_POST["T2"]; $S1=$_POST["S1"]; mysql_select_db($db); $sql = "UPDATE `guestbook`.`gbook` SET `name` = '$T1', `sex` = '$R1', `email` = '$T2', `info` = '$S1' WHERE `gbook`.`id` = '$id' LIMIT 1;"; $result=mysql_query($sql); if ($result) { echo "修改成功"; } else { echo "修改失败"; } ?> <html> <head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>修改成功</title> </head> <body> <p><a href="index.html"><继续留言></a></p> </body> </html>