知识屋:更实用的电脑技术知识网站
所在位置:首页 > 编程技术 > PHP编程

php实战第十一天

发布时间:2015-05-27 19:27:00作者:知识屋

今天学习了做安装包
这里是HTML模板
[html]
<!DOCTYPE html> 
<html lang="en"> 
<head> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  <title>瀑布流留言板管理系统</title> 
  <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css"></head> 
 
 
<body> 
<div class="container"> 
<div class="container-fluid"> 
    <div class="row-fluid"> 
      <div class="span4"> 
        <h3>瀑布流记事本安装包</h3> 
      </div> 
    </div> 
</div> 
 
 
    <form class="form-horizontal" action="install.php" method="post" > 
      <div class="control-group"> 
        <label class="control-label" for="content">MYSQL主机</label> 
        <div class="controls"> 
          <input class="span4" type="text" name="m_server" value="localhost" placeholder="mysql数据库的地址"> 
          <span class="help-inline">你的数据库所在IP,一般是localhost</span> 
        </div> 
      </div> 
 
 
      <div class="control-group"> 
        <label class="control-label" for="userName">数据库用户名</label> 
        <div class="controls"> 
          <input class="span4" type="text" name="m_userName" value="root" placeholder="mysql数据库登陆用户名"> 
          <span class="help-inline">你的MySQL帐户。</span> 
 
 
        </div> 
      </div> 
 
 
      <div class="control-group"> 
        <label class="control-label" for="userName">数据库密码</label> 
        <div class="controls"> 
          <input class="span4" type="text" name="m_password" value="1234" placeholder="mysql数据库登陆密码"> 
          <span class="help-inline">你的MySQL密码。</span> 
        </div> 
      </div> 
 
 
      <div class="control-group"> 
        <label class="control-label" for="userName">数据库名称</label> 
        <div class="controls"> 
          <input class="span4" type="text" name="m_dbName" value="db_liuyan" placeholder="数据库名称"> 
          <span class="help-inline">你的数据库名称,请先确认此数据库存在。</span> 
        </div> 
      </div> 
 
 
 
 
      <div class="control-group"> 
        <label class="control-label" for="userName">网站的标题</label> 
        <div class="controls"> 
          <input class="span4" type="text" name="c_title" value="我的瀑布流留言板" placeholder="网站的标题"> 
          <span class="help-inline">设置网站的标题</span> 
        </div> 
      </div> 
 
 
 
 
      <div class="control-group"> 
        <label class="control-label" for="userName">后台登陆用户名</label> 
        <div class="controls"> 
          <input class="span4" type="text" name="adminUser" value="admin" placeholder="后台登陆用户名"> 
          <span class="help-inline">登陆后台所用的用户名</span> 
        </div> 
      </div> 
 
 
      <div class="control-group"> 
        <label class="control-label" for="userName">后台登陆密码</label> 
        <div class="controls"> 
          <input class="span4" type="text" name="adminPassword" value="admin" placeholder="后台登陆密码"> 
          <span class="help-inline">登陆后台所用的密码</span> 
        </div> 
      </div> 
 
 
      <div class="control-group"> 
        <div class="controls"> 
        <input class="btn btn-info" type="submit" name="submit" value="安装"> 
        </div> 
      </div> 
    </form> 
</div> 
 
 
</body> 
    <script src="../js/jquery-2.0.1.min.js"></script> 
    <script type="text/javascript" src="../js/bootstrap.min.js"></script> 
 
 
 
 
</html> 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>瀑布流留言板管理系统</title>
  <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css"></head>


<body>
<div class="container">
<div class="container-fluid">
    <div class="row-fluid">
      <div class="span4">
        <h3>瀑布流记事本安装包</h3>
      </div>
    </div>
</div>


    <form class="form-horizontal" action="install.php" method="post" >
      <div class="control-group">
        <label class="control-label" for="content">MYSQL主机</label>
        <div class="controls">
          <input class="span4" type="text" name="m_server" value="localhost" placeholder="mysql数据库的地址">
          <span class="help-inline">你的数据库所在IP,一般是localhost</span>
        </div>
      </div>


      <div class="control-group">
        <label class="control-label" for="userName">数据库用户名</label>
        <div class="controls">
          <input class="span4" type="text" name="m_userName" value="root" placeholder="mysql数据库登陆用户名">
          <span class="help-inline">你的MySQL帐户。</span>


        </div>
      </div>


      <div class="control-group">
        <label class="control-label" for="userName">数据库密码</label>
        <div class="controls">
          <input class="span4" type="text" name="m_password" value="1234" placeholder="mysql数据库登陆密码">
          <span class="help-inline">你的MySQL密码。</span>
        </div>
      </div>


      <div class="control-group">
        <label class="control-label" for="userName">数据库名称</label>
        <div class="controls">
          <input class="span4" type="text" name="m_dbName" value="db_liuyan" placeholder="数据库名称">
          <span class="help-inline">你的数据库名称,请先确认此数据库存在。</span>
        </div>
      </div>

 


      <div class="control-group">
        <label class="control-label" for="userName">网站的标题</label>
        <div class="controls">
          <input class="span4" type="text" name="c_title" value="我的瀑布流留言板" placeholder="网站的标题">
          <span class="help-inline">设置网站的标题</span>
        </div>
      </div>

 


      <div class="control-group">
        <label class="control-label" for="userName">后台登陆用户名</label>
        <div class="controls">
          <input class="span4" type="text" name="adminUser" value="admin" placeholder="后台登陆用户名">
          <span class="help-inline">登陆后台所用的用户名</span>
        </div>
      </div>


      <div class="control-group">
        <label class="control-label" for="userName">后台登陆密码</label>
        <div class="controls">
          <input class="span4" type="text" name="adminPassword" value="admin" placeholder="后台登陆密码">
          <span class="help-inline">登陆后台所用的密码</span>
        </div>
      </div>


      <div class="control-group">
        <div class="controls">
        <input class="btn btn-info" type="submit" name="submit" value="安装">
        </div>
      </div>
    </form>
</div>


</body>
    <script src="../js/jquery-2.0.1.min.js"></script>
    <script type="text/javascript" src="../js/bootstrap.min.js"></script>

 


</html>


下面是php代码
[php]
<?php  
     
    //var_dump($_POST);  
    $server =$_POST['m_server']; 
    $userName=$_POST['m_userName']; 
    $password=$_POST['m_password']; 
    $dbName=$_POST['m_dbName']; 
     
    $adminUser=$_POST['adminUser']; 
    $adminPassword=md5($_POST['adminPassword']); 
    $title=$_POST['c_title']; 
 
 
 
 
 
 
    include '../function.php'; 
 
 
    $c=config_get('../config.php'); 
    $c['dbServer']=$server; 
    $c['dbUserName']=$userName; 
    $c['dbPassword']=$password; 
    $c['dbName']=$dbName; 
    $c['title']=$title; 
    $c['footer']='已经滚动到底部了'; 
    //$c['adminUser']=$adminUser;  
    //$c['adminPassword']=$adminPassword;  
    config_set("../config.php",$c); 
 
 
    //var_dump($GLOBALS);  
    $conn=mysql_connect($server,$userName,$password)or die("mysql连接失败 错误信息:" . mysql_error()); 
 
 
    /**
    * 选择数据库,如果不存在则自动创建
    */ 
    if(!mysql_select_db($dbName)){ 
        $query='CREATE DATABASE '.$dbName; 
        $result = mysql_query($query)or die("1Invalid query: " . mysql_error()); 
        if(!$result){ 
            echo "创建数据库失败,请手动创建 {$dbName}"; 
            exit(); 
        } 
        mysql_select_db($dbName); 
    } 
 
 
    /**
    * 创建data表,用于留言记录
    */ 
    $query="CREATE TABLE IF NOT EXISTS `data` ( 
  `id` int(11) NOT NULL AUTO_INCREMENT, 
  `time` int(10) NOT NULL, 
  `userName` varchar(200) COLLATE utf8_unicode_ci NOT NULL, 
  `content` text COLLATE utf8_unicode_ci NOT NULL, 
  `email` varchar(40) COLLATE utf8_unicode_ci NOT NULL, 
  PRIMARY KEY (`id`) 
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=26"; 
 
 
    $result = mysql_query($query)or die("创建数据表 'data' 失败 错误信息:" . mysql_error()); 
 
 
    /**
    * 创建user表,用于用户管理
    */ 
    $query="CREATE TABLE IF NOT EXISTS `user` ( 
      `id` int(11) NOT NULL AUTO_INCREMENT, 
      `userName` text NOT NULL, 
      `password` varchar(40) NOT NULL, 
      `time` int(11) NOT NULL, 
      PRIMARY KEY (`id`) 
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2"; 
 
 
    $result = mysql_query($query)or die("创建数据表 'user' 失败 错误信息:" . mysql_error()); 
 
 
 
 
    //插入user表用户  
    $query="INSERT INTO `user` (`id`, `userName`, `password`, `time`)  
            VALUES (1, '{$adminUser}', '{$adminPassword}', 1369417030)"; 
 
 
    $result = mysql_query($query); 
    if (!$result) { 
        echo ("'user'表,插入数据失败 错误信息:".mysql_error()); 
    } 
 
 
    echo "安装成功"; 
 
 
    //header("Localhost: ./admin.php?m=admin&a=index");  
    //echo "<script>window.location.href='../admin.php?m=admin&a=login';</script>";  
/*
 
 
*/ 
 
 
 ?> 

<?php
 
 //var_dump($_POST);
 $server =$_POST['m_server'];
 $userName=$_POST['m_userName'];
 $password=$_POST['m_password'];
 $dbName=$_POST['m_dbName'];
 
 $adminUser=$_POST['adminUser'];
 $adminPassword=md5($_POST['adminPassword']);
 $title=$_POST['c_title'];

 

 


 include '../function.php';


 $c=config_get('../config.php');
 $c['dbServer']=$server;
 $c['dbUserName']=$userName;
 $c['dbPassword']=$password;
 $c['dbName']=$dbName;
 $c['title']=$title;
 $c['footer']='已经滚动到底部了';
 //$c['adminUser']=$adminUser;
 //$c['adminPassword']=$adminPassword;
 config_set("../config.php",$c);


 //var_dump($GLOBALS);
 $conn=mysql_connect($server,$userName,$password)or die("mysql连接失败 错误信息:" . mysql_error());


 /**
 * 选择数据库,如果不存在则自动创建
 */
 if(!mysql_select_db($dbName)){
  $query='CREATE DATABASE '.$dbName;
  $result = mysql_query($query)or die("1Invalid query: " . mysql_error());
  if(!$result){
   echo "创建数据库失败,请手动创建 {$dbName}";
   exit();
  }
  mysql_select_db($dbName);
 }


 /**
 * 创建data表,用于留言记录
 */
 $query="CREATE TABLE IF NOT EXISTS `data` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `time` int(10) NOT NULL,
  `userName` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
  `content` text COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=26";


 $result = mysql_query($query)or die("创建数据表 'data' 失败 错误信息:" . mysql_error());


 /**
 * 创建user表,用于用户管理
 */
 $query="CREATE TABLE IF NOT EXISTS `user` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `userName` text NOT NULL,
   `password` varchar(40) NOT NULL,
   `time` int(11) NOT NULL,
   PRIMARY KEY (`id`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2";


 $result = mysql_query($query)or die("创建数据表 'user' 失败 错误信息:" . mysql_error());

 


 //插入user表用户
 $query="INSERT INTO `user` (`id`, `userName`, `password`, `time`)
   VALUES (1, '{$adminUser}', '{$adminPassword}', 1369417030)";


 $result = mysql_query($query);
 if (!$result) {
  echo ("'user'表,插入数据失败 错误信息:".mysql_error());
 }


 echo "安装成功";


 //header("Localhost: ./admin.php?m=admin&a=index");
 //echo "<script>window.location.href='../admin.php?m=admin&a=login';</script>";
/*


*/


 ?>


 

(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)
收藏
  • 人气文章
  • 最新文章
  • 下载排行榜
  • 热门排行榜