| //选择操作的数据库 mysql_select_db($link_db,$link); //建立表格 $link_table = "create table link_table ( link_id int unsigned primary key not null auto_increment, link_name varchar(20) not null, link_url varchar(50) not null, link_detail varchar(100) not null, link_contact varchar(100) not null, link_show int unsigned not null, link_order int unsigned not null, link_sort int unsigned not null )"; $sort_table = "create table sort_table ( sort_id int unsigned primary key not null auto_increment, sort_name varchar(20) not null )"; //执行建表操作 if(!mysql_query($link_table,$link)){ echo "Create link_table error :" . mysql_error() . " "; } else { echo "link_table Created!" . " "; } if(!mysql_query($sort_table,$link)){ echo "Create sort_table error :" . mysql_error() . " "; } else { echo "sort_table Created!" . " "; } //执行完毕关闭数据库连接 mysql_close($link); ?> 首先建立一个表格,用来填写需要向MySQL数据库写入的数据: #写入数据库 | 代码如下 | 复制代码 | //insert.php 网站名称: 网站链接: 简介: 联系方式: 排序: 分类: 是否显示: 里其他的都是用文本框输入,而是否显示使用复选框来实现,默认选中。 执行写入的程序页面 | 代码如下 | 复制代码 | //insert_ok.php include ("conn.php"); //读取上个页面中表单中的数据 $link_name=$_POST[site_name]; $link_url=$_POST[site_url]; $link_contact=$_POST[site_contact]; $link_detail=$_POST[site_detail]; $link_order=$_POST[site_order]; $link_sort=$_POST[site_sort]; $link_show=$_POST[site_show]; if (!$link_show=="1") $link_show="0"; //复选框是否选中,如果没有选中则赋值为0 mysql_select_db("link_system", $link); //选择数据库link_system if($_POST) { $sql = "INSERT INTO link_table (link_name,link_url,link_contact,link_detail,link_order,link_sort,link_show) VALUES ('$link_name','$link_url','$link_contact','$link_detail','$link_order','$link_sort','$link_show')"; if(!mysql_query($sql,$link)) { echo "添加数据失败:".mysql_error(); } else { echo "添加数据成功!"; echo $_POST[site_name]." ".$_POST[site_url]." ".$_POST[site_contact]." ".$_POST[site_detail]." ".$_POST[site_order]." ".$_POST[site_sort]." ".$_POST[site_show]; } } ?> 如果执行成功,则添加友链数据完成,至于分类暂时先不添加,到后期再将分类加入里面。下一步则是显示数据、编辑数据和删除数据的实现了。 |
|
|