<?php require_once "connect.php"; echo <<<_END <!DOCTYPE HTML> <html dir="ltr" lang="zh-CN"> <head> <meta charset="utf-8"> <title></title> </head> <body> <form action="sql_test.php" method="post"> <fieldset> <legend>ADD DEMO</legend> <p> <label for="name">Name: </label> <input type="text" name="name"/> </p> <p> <label for="age">Age: </label> <input type="text" name="age"/> </p> <p> <label for="sex">Sex: </label> <input type="text" name="sex"/> </p> </fieldset> <fieldset> <input type="submit" name="add_submit" value="提交"/> <input type="reset" value="重置"/> </fieldset> </form> </body> </html> _END; if (isset($_POST["name"]) && isset($_POST["age"]) && isset($_POST["sex"]) && isset($_POST["add_submit"])) { $name=$_POST["name"]; $age=$_POST["age"]; $sex=$_POST["sex"]; } if(isset($_POST["add_submit"])){ mysql_query("set names utf8"); $add_query="insert into users(name,age,sex) values('$name','$age','$sex')"; mysql_query($add_query); } mysql_query("set names utf8"); $select_query="select * from users"; $results=mysql_query($select_query); while ($rows=mysql_fetch_row($results)) { echo "Id:".$rows[0]."<br>"; echo "Name:".$rows[1]."<br>"; echo "Age:".$rows[2]."<br>"; echo "Sex:".$rows[3]."<br>"."<br>"."<br>"; } echo <<<_END <form action="sql_test.php" method="post"> <fieldset> <legend>DELETE DEMO</legend> <p> <label for="id">ID: </label> <input type="text" name="id"/> </p> </fieldset> <fieldset> <input type="submit" name="del_submit" value="提交"/> <input type="reset" value="重置"/> </fieldset> </form> _END; if(isset($_POST["id"]) && isset($_POST["del_submit"])){ $id=$_POST["id"]; } if(isset($_POST["del_submit"])){ $del_query="delete from users where id='$id'"; mysql_query($del_query); } mysql_query("set names utf8"); $select_query="select * from users"; $results=mysql_query($select_query); while ($rows=mysql_fetch_row($results)) { echo "Id:".$rows[0]."<a href='sql_test?'>Edit</a>"."<br>"; echo "Name:".$rows[1]."<br>"; echo "Age:".$rows[2]."<br>"; echo "Sex:".$rows[3]."<br>"."<br>"."<br>"; } echo <<<_END <form action="sql_test.php" method="post"> <fieldset> <legend>UPDATE DEMO</legend> <p> <label for="id">ID: </label> <input type="text" name="id"/> </p> <p> <label for="name">Name: </label> <input type="text" name="name"/> </p> <p> <label for="age">Age: </label> <input type="text" name="age"/> </p> <p> <label for="sex">Sex: </label> <input type="text" name="sex"/> </p> </fieldset> <fieldset> <input type="submit" name="update_submit" value="提交"/> <input type="reset" value="重置"/> </fieldset> </form> _END; if(isset($_POST["name"]) && isset($_POST["age"]) && isset($_POST["sex"]) && isset($_POST["update_submit"])){ $name=$_POST["name"]; $age=$_POST["age"]; $sex=$_POST["sex"]; $id=$_POST["id"]; } if(isset($_POST["update_submit"])){ $up_query="update users set name='$name',age='$age',sex='$sex' where id='$id'"; mysql_query($up_query); } mysql_query("set names utf8"); $select_query="select * from users"; $results=mysql_query($select_query); while ($rows=mysql_fetch_row($results)) { echo "Id:".$rows[0]."<a href='sql_test?'>Edit</a>"."<br>"; echo "Name:".$rows[1]."<br>"; echo "Age:".$rows[2]."<br>"; echo "Sex:".$rows[3]."<br>"."<br>"."<br>"; } echo <<<_END <form action="sql_test.php" method="post"> <fieldset> <legend>SELECT DEMO</legend> <p> <label for="id">ID: </label> <input type="text" name="id"/> </p> <p> <label for="name">Name: </label> <input type="text" name="name"/> </p> <p> <label for="age">Age: </label> <input type="text" name="age"/> </p> <p> <label for="sex">Sex: </label> <input type="text" name="sex"/> </p> </fieldset> <fieldset> <input type="submit" name="select_submit" value="提交"/> <input type="reset" value="重置"/> </fieldset> </form> _END; if (isset($_POST["select_submit"])) { if(isset($_POST["name"])){ $name=$_POST["name"]; $sel_results=mysql_query("select * from users where name='$name'"); while ($rows=mysql_fetch_row($sel_results)) { echo "id: ".$rows[0]."<br>"; echo "name: ".$rows[1]."<br>"; echo "age: ".$rows[2]."<br>"; echo "sex: ".$rows[3]."<br>"."<br>"; } } if (isset($_POST["age"])) { $age=$_POST["age"]; $sel_results=mysql_query("select * from users where age='$age'"); while ($rows=mysql_fetch_row($sel_results)) { echo "id: ".$rows[0]."<br>"; echo "name: ".$rows[1]."<br>"; echo "age: ".$rows[2]."<br>"; echo "sex: ".$rows[3]."<br>"."<br>"; } } if (isset($_POST["sex"])) { $sex=$_POST["sex"]; $sel_results=mysql_query("select * from users where sex='$sex'"); while ($rows=mysql_fetch_row($sel_results)) { echo "id: ".$rows[0]."<br>"; echo "name: ".$rows[1]."<br>"; echo "age: ".$rows[2]."<br>"; echo "sex: ".$rows[3]."<br>"."<br>"; } } if (isset($_POST["id"])) { $id=$_POST["id"]; $sel_results=mysql_query("select * from users where id='$id'"); while ($rows=mysql_fetch_row($sel_results)) { echo "id: ".$rows[0]."<br>"; echo "name: ".$rows[1]."<br>"; echo "age: ".$rows[2]."<br>"; echo "sex: ".$rows[3]."<br>"."<br>"; } # code... } } ?>