标签:
这次我们来一个个的编写文件
1.首先当然是基础配置文件的编写,第一个config.php
<?php header("Content-type:text/html; charset:utf-8"); define(‘HOST‘,‘localhost‘); define(‘USERNAME‘,‘root‘); define(‘PASSWORD‘,‘root‘); ?>
里面是我电脑上mysql的登录端口,账户,密码的信息,你们的也大同小异吧
2.第二个写的是connect.php文件
<?php require_once(‘config.php‘); //配置文件 if(!($con=mysql_connect(HOST,USERNAME,PASSWORD))){ echo mysql_error(); } //连接数据库 if(!(mysql_select_db(‘test‘))){ echo mysql_error(); } //选择数据库 if(!(mysql_query(‘set names utf-8‘))){ echo mysql_error(); } //定义字符集 ?>
这个是初始化连接数据库的文件,每个函数都要检测是否成功,有错误则输出。需注意的是最后一个定义字符集为“utf-8”,则以后的文件里的字符集都需统一,否则会有乱码。
3.发布界面与程序
前面定义:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题</title> <style type="text/css"> body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } </style> </head>
body内容:
<body> <table width="100%" height="520" border="0" cellpadding="8" cellspacing="1" bgcolor="#000000"> <tr> <td height="30" colspan="2" bgcolor="#FFFF99"><strong>后台管理系统</strong></td> </tr> <tr> <td width="156" height="287" align="left" valign="top" bgcolor="#FFFF99"><p><a href="article.add.php">发布文章 </a></p> <p><a href="article.manage.php">管理文章</a></p> <a href="article.add.php"></a></td> <td width="837" valign="top" bgcolor="#FFFFFF"> <form id="form1" name="form1" method="post" action="article.add.handle.php"> <table width="779" border="0" cellpadding="8" cellspacing="1"> <tr> <td colspan="2" align="center">发布文章</td> </tr> <tr> <td width="119">标题</td> <td width="625"><label for="title"></label> <input type="text" name="title" id="title" /></td> </tr> <tr> <td>作者</td> <td><input type="text" name="author" id="author" /></td> </tr> <tr> <td>简介</td> <td><label for="description"></label> <textarea name="description" id="description" cols="60" rows="5"></textarea></td> </tr> <tr> <td>内容</td> <td><textarea name="content" cols="60" rows="15" id="content"></textarea></td> </tr> <tr> <td colspan="2" align="right"><input type="submit" name="button" id="button" value="提交" /></td> </tr> </table> </form></td> </tr> <tr> <td colspan="2" bgcolor="#FFFF99"><strong>版权所有</strong></td> </tr> </table> </body> </html>
标签:
原文地址:http://www.cnblogs.com/ly550275752/p/4950580.html