PHP增删改查的容易实现
come from http://hi.baidu.com/javashmily/item/69d117fc3ebbdd723d198b9e
//获得连接
$db = mysql_connect("localhost", "root", "root") or die(mysql_error());
echo "Connected to MySQL
";
//连接数据库
mysql_select_db("php") or die(mysql_error());
echo "Connected to Database";
//增加操作
if ($submit){????????????????????????????????????????????????????????????????
??? $sql = "INSERT INTO student (id,name) VALUES ('$id','$name')";??????????????????
??? $result = MySQL_query($sql);????????????????????????????????????
??? echo "记录添加成功!
";?????????????????????????????????
??? }
??? //删除操作
??? if($delete){
??? $sql ="delete from student where id = $id";
??? $result = mysql_query($sql);
??? echo "删除了id为 $id 的记录 ";
??? }
??? //修改操作
??? if($update){
??? $sql = "update student set name='$name' where id = $id";
??? $result = mysql_query($sql);
??? echo "修改成功!!";
??? }
??? //查询数据,并用表格显示出来
??? $result = mysql_query("select * from student",$db);
echo "
id | 姓名 | ";?????????????????????????????????????????????????????
%s | %s | ", $myrow[0], $myrow[1]);
?>
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
推荐阅读
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论