
<?php
if ($_POST[dbhost]) {
$hostname=htmlspecialchars($_POST[dbhost]);
$username=htmlspecialchars($_POST[dbuser]);
$password=htmlspecialchars($_POST[dbpwd]);
$database=htmlspecialchars($_POST[dbname]);
$adminname=htmlspecialchars($_POST[adminuser]);
$adminpass=md5($_POST[adminpwd]);

mysql_connect($hostname,$username,$password) or die ("数据库连接失败");
mysql_query("create database if not exists $database  DEFAULT CHARACTER SET gb2312 COLLATE gb2312_chinese_ci;");
mysql_select_db($database) or die ("没有相应的数据库");
$conn_file=file_get_contents("../include/conn.php");
$conn_file=str_replace("hostname_db",$hostname,$conn_file);
$conn_file=str_replace("username_db",$username,$conn_file);
$conn_file=str_replace("password_db",$password,$conn_file);
$conn_file=str_replace("name_data",$database,$conn_file);
file_put_contents("../include/conn.php",$conn_file);
$sql_file=file_get_contents("sqlyongliol.sql");
$ar = split( ";",$sql_file);
	foreach ($ar as $v) {
		mysql_query("set names 'utf8'");
		@mysql_query($v);
	}
	mysql_query("update admin set username='$adminname',password='$adminpass'");
	mysql_query("insert into `db`(hostname,username,userpwd,dbname) VALUES ('$hostname','$username','$password','$database')");
	
	
	file_put_contents("lock.txt","1");
	header('Location: step4.php');
	
}


?>
