数据库添加数据I
2016-06-27 18:45
387 查看
/*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); } ?>
相关文章推荐
- mysql auto_increment 初始值从0开始
- mysql 主从复制
- MongoDB 几个小命令
- php CI框架中调用接口 memcache缓存数据
- 数据库删除操作
- Hive-0.13.1本地独立模式安装 元数据存储到MariaDB-10.1.0 Hadoop-2.4.0
- 数据库操作
- oracle
- 【Mysql】mysql查询超时JDBC源码浅析
- jsp中使用动态数据进行mySQL数据库的两种操作方法
- mysqldump和mydumper的比较
- MYSQL性能查看(命中率,慢查询)
- 数据库事务的理解
- TimesTen 数据库复制学习:8. 管理Active Standby Pair(带缓存组)
- MySQL 索引分析
- window下mysql安装以及问题解决方法
- myBatis数据库连接配置错误
- oracle中的替换函数replace和translate函数
- MySQL出现SQL Error (2013)连接错误的解决方法
- MySQL行级锁、表级锁、页级锁详细介绍