程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php實戰第十一天

php實戰第十一天

編輯:關於PHP編程

今天學習了做安裝包
這裡是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>";
/*


*/


 ?>


 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved