标签:
/*insert.php*/ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf8" /> <title>insert</title> </head> <center> <body> <form name="from1" action="insert.php" method="post"> <table border="1" width="30%"> <tr> <td colspan="2" align="center">添加学生</td> </tr> <tr> <td align="center">编号</td> <td><input type="text" name="id"></td> </tr> <tr> <td align="center">姓名</td> <td><input type="text" name="name"></td> </tr> <tr> <td align="center">性别</td> <td> <input type="radio" name="sex" value="男" checked=‘checked‘>男 <input type="radio" name="sex" value="女">女 </td> </tr> <tr> <td align="center">年龄</td> <td> <select name="age"> <?php for($i=10;$i<30;$i++) { ?> <option value="<?php echo $i?>"><?php echo $i?>岁</option> <?php } ?> </select> </td> </tr> <tr> <td colspan="2" align="center"><input name="Submit" type="submit" value="保存"> <a href=‘sy.php‘><input name="return" type="button" value="返回" ></a></td> </tr> </table> </form> </body> </center> </html> <?php //检查是否正在提交表单 if($_SERVER[‘REQUEST_METHOD‘]=="POST"){ $conn=mysql_connect("localhost","root","root"); $select_db=mysql_select_db("test"); $name=$_POST[‘name‘]; $id=$_POST[‘id‘]; $sex=$_POST[‘sex‘]; $age=$_POST[‘age‘]; mysql_query("set names utf8"); $insert=mysql_query("insert into stu (stu_id,stu_name,stu_age,stu_sex) values (‘$id‘,‘$name‘,‘$age‘,‘$sex‘)"); //往数据库中添加数据 if($insert) { //echo "<script>alert(‘Insert seccssed!‘)</script>"."<br>"; //echo "添加成功!"; header("location:sy.php"); } else { echo "出错了!<br>"; die(mysql_error()); //echo "<script>alert(‘insert wrong!‘)</script>"."<br>"; } mysql_close($conn); } ?>
标签:
原文地址:http://www.cnblogs.com/-beyond/p/5621235.html