PHP+MySQL 制作简单的留言本

PHP+MySQL 制作简单的留言本

留言显示页面:比上一个例子增加了分页和留言回复的功能

PHP+MySQL 制作简单的留言本

主要代码:
install/index.php:程序安装页面

复制代码 代码如下:


<?php
if($_GET["action"]!=1)
{
?>
<form method="post" action="index.php?action=1">
<table>
<tr>
<td>MySQL主机名:</td>
<td><input type="text" value="localhost"></td>
</tr>
<tr>
<td>MySQL用户名:</td>
<td><input type="text" value="root"></td>
</tr>
<tr>
<td>MySQL密码:</td>
<td><input type="password" value=""></td>
</tr>
<tr>
<td>数据库名称:</td>
<td><input type="text" value="ruizhi_messageboard"></td>
</tr>
<tr>
<td>留言本每页记录数:</td>
<td><input type="text" value="10"></td>
</tr>
<tr>
<td>管理员账号:</td>
<td><input type="text" value="admin"></td>
</tr>
<tr>
<td>管理员密码:</td>
<td><input type="text" value="admin"></td>
</tr>
<tr>
<td>留言本标题:</td>
<td><input type="text" value="RUIZHINET留言本"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="确定安装"> <input type="button" value="关闭页面"></td>
<td></td>
</tr>
</table>
</form>
<?php
}else{
@set_time_limit(1000);
$lockfile = "install.lock";
$host="localhost";
$user="root";
$password="";
$database="ruizhi_messageboard";
$pagenum=10;
$admin_name="admin";
$admin_password="123456";
$boardname="RUIZHINET留言本";
if($_POST["host"]!=""){
$host=$_POST["host"];
}
if($_POST["user"]!=""){
$user=$_POST["user"];
}
if($_POST["password"]!=""){
$password=$_POST["password"];
}
if($_POST["database"]!=""){
$database=$_POST["database"];
}
if($_POST["pagenum"]!=""){
$pagenum=$_POST["pagenum"];
}
if($_POST["admin_name"]!=""){
$admin_name=$_POST["admin_name"];
}
if($_POST["admin_password"]!=""){
$admin_password=$_POST["admin_password"];
}
if($_POST["boardname"]!=""){
$boardname=$_POST["boardname"];
}
if(file_exists($lockfile)){
exit("已经安装过了,如果要重新安装请先删除install/install.lock");
}
$conn=mysql_connect($host,$user,$password);
if($conn){
$sql_drop_database="DROP DATABASE IF EXISTS `".$database."`";
$sql_create_database="CREATE DATABASE `".$database."`";
$sql_create_table_messageboard="CREATE TABLE `messageboard` (
`id` int(11) NOT NULL auto_increment,
`author` varchar(15) NOT NULL,
`title` varchar(30) NOT NULL,
`smiles` varchar(30) NOT NULL,
`content` mediumtext,
`photo` varchar(30) NOT NULL,
`addtime` int(11) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk AUTO_INCREMENT=1";
$sql_create_table_reply="CREATE TABLE `reply` (
`id` int(11) NOT NULL auto_increment,
`msgid` int(11) NOT NULL,
`content` mediumtext,
`addtime` int(11) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk AUTO_INCREMENT=1";
if(mysql_query($sql_drop_database,$conn)){
if(mysql_query($sql_create_database,$conn)){
mysql_select_db($database,$conn);
if(mysql_query($sql_create_table_messageboard,$conn) && mysql_query($sql_create_table_reply,$conn)){
$config_file="../config.php";
$config_strings="<?php\n";
$config_strings.="\$boardname=\"".$boardname."\";\n";
$config_strings.="\$host=\"".$host."\";\n";
$config_strings.="\$user=\"".$user."\";\n";
$config_strings.="\$password=\"".$password."\";\n";
$config_strings.="\$database=\"".$database."\";\n";
$config_strings.="\$pagenum=\"".$pagenum."\";\n";
$config_strings.="\$admin_name=\"".$admin_name."\";\n";
$config_strings.="\$admin_password=\"".$admin_password."\";\n";
$config_strings.="\$conn=mysql_connect(\$host,\$user,\$password);\n";
$config_strings.="mysql_select_db(\$database,\$conn);\n";
$config_strings.="?>";
if($fp=fopen($config_file,"wb")){
if(fwrite($fp,$config_strings)){
if($fp2 = fopen($lockfile, 'w'))
{
fwrite($fp2,'1212');
fclose($fp2);
}
echo "安装成功!配置文件为:config.php,您可以手工修改该文件";
echo "\n<a href='https://www.jb51.net/index.php'>进入系统首页</a>";
}else{
exit("文件写入失败");
}
fclose($fp);
}
}else{
exit("不能执行CREATE TABLE语句:".$sql_create_table);
}
}else{
exit("不能执行CREATE DATABASE语句:".$sql_create_database);
}
}else{
exit("不能执行DROP DATABASE语句:".$sql_drop_database);
}
}else{
exit("连接数据库失败,请检查MySQL主机名、用户名和密码");
}
}


生成的config.php文件:

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/d323bde64ed9ba88034f4ae05356a5d8.html