您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP类别表的管理方法

2025/7/31 22:27:04发布20次查看
本篇文章主要介绍php类别表的管理方法,感兴趣的朋友参考下,希望对大家有所帮助。
创建一个数据库:
create table if not exists `class_add` ( `id` int(4) not null auto_increment, `class_name` varchar(100) not null, primary key (`id`) ) engine=innodb default charset=latin1 auto_increment=12 ;
代码如下:
index.html
<html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>添加分类</title> </head> <body> <form action="add.php" method="post"> 类别:<input type="text" name="class_name"/><br><br> <input type= "submit" value="添加"/> </form> </body> </html>
add.php
<?php $class_name = $_post['class_name']; //获取表单提交数据 $conn = mysql_connect("localhost","root","111111"); //链接数据库 if(!$conn) //链接数据库判断 { die("连接数据库失败".mysql_error()); } //选择数据库 mysql_select_db("class_add") or die("数据库选择失败".mysql_error()); mysql_query("set names 'uft8'"); //需要使用的sql语句 $sql = "insert into class_add(class_name) values ('$class_name')"; //执行sql语句 $result = mysql_query($sql,$conn); //判断sql语句是否执行成功 if(!$result) { echo '数据插入失败!'.mysql_error(); exit; } mysql_close($conn);//断开与数据库的链接 include("index.html");//返回类别添加页面 ?>
select.php
<html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>调用分类</title> </head> <body> <?php $conn = mysql_connect("localhost","root","111111"); if(!$conn) { die("连接数据库失败".mysql_error()); } mysql_select_db("class_add") or die("数据库选择失败".mysql_error()); mysql_query("set names 'uft8'"); $sql = "select class_name from class_add"; $result = mysql_query($sql,$conn); ?> <form action="test.php" method="post"> <select name="class_name" size="1"> <?php //数据库获取的数据是以数组形式表示的 while($row = mysql_fetch_row($result)) { foreach($row as $key=>$key_val) { echo "<option value=".$key_val.">".$key_val."</option>"; } echo "<br/>"; } ?> </select> <input type= "submit" value="确定"/> </form> </body> </html>
test.php
<?php $class_name = $_post['class_name']; echo $class_name; ?>
相关推荐:
php和ajax实现文章添加类别功能
php设计模式类别实例详解
phpcms的分类名称和类别名称的调用
以上就是php类别表的管理方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product