<?php
header("content-type:text/html;charset=utf-8");
error_reporting(0);
if(file_exists("../myadmin/sql.php")){exit;}
$sever=$_POST['sever'];
$mysql_name=$_POST['mysql_name'];
$mysql_zhanghao=$_POST['mysql_zhanghao'];
$mysql_password=$_POST['mysql_password'];
$admin_zhanghao=$_POST['admin_zhanghao'];
$admin_password=$_POST['admin_password'];
$password_wenti=$_POST['password_wenti'];
$password_daan=$_POST['password_daan'];
$con=mysql_connect($sever,$mysql_zhanghao,$mysql_password) or die("<script>alert('数据库连接失败');history.go(-1)</script>");

$select_db=mysql_select_db($mysql_name) or die("<script>alert('数据库名有误');history.go(-1)</script>");

mysql_query("set names utf8");
$str_sql="<?php\r\n";
$str_sql.="\$con=mysql_connect("."'".$sever."',"."'".$mysql_zhanghao."',"."'".$mysql_password."'".");\r\n";
$str_sql.="mysql_select_db('{$mysql_name}');\r\n";
$str_sql.="mysql_query('set names utf8');\r\n";
$str_sql.="?>";
    if(!file_put_contents("../myadmin/sql.php",$str_sql)){exit;echo "<script>alert('没有读写权限，请打开读写权限。');history.go(-1)</script>";}
    $install = file_get_contents("sl.sql");
    $install = explode(";",$install);
    foreach($install AS $sqla => $sqlb){
        $inserror=mysql_query($sqlb) or die (mysql_error());
       }
       file_put_contents("qq.txt",$_SERVER['HTTP_HOST']);
    $admin_sql="insert into admin(admin,password,mimawenti,nimawenti2) values('{$admin_zhanghao}','{$admin_password}','{$password_wenti}','{$password_daan}')";
    mysql_query($admin_sql);
    rename("index.php","index.slphp");
    rename("sl.sql","sl.slphp");
  echo "<script>alert('恭喜安装成功！');location='../myadmin/admin/admin.php';</script>";

?>