:::

12-1 index.php

<?php
//引入共同檔
require_once "header.php";

//變數初始化
$op=isset($_REQUEST['op'])?$_REQUEST['op']:"";
//$class_sn=isset($_REQUEST['class_sn'])?intval($_REQUEST['class_sn']):"";

//流程控制
switch($op){

  case "insert_article":
  insert_article();
  header("location:{$_SERVER['PHP_SELF']}");
  break;

  default:
  $main=article_form();
  break;
}


//套用樣板
theme("theme.html");

/*************** 功能函數區 **************/

//輸入學習收藏的表單
function article_form(){
  $now_seme=get_seme();

  $sql="select class_sn,class_name from tncomu_class where access='1' and seme='{$now_seme}' ";
  $result=mysql_query($sql);
  $opt="";
  while(list($class_sn,$class_name)=mysql_fetch_row($result)){
    $opt.="<option value='$class_sn'>$class_name</option>";
  }


  $main="<h3 style='color:#0066CC'>輸入學習收藏</h3>
  <form action='{$_SERVER['PHP_SELF']}' method='post'>
    <table>
      <tr>
        <th>您的姓名:</th>
        <td><input type='text' name='stud_name' size='10'></td>
        <th>{$now_seme}班級:</th>
        <td>
          <select name='class_sn'>
            <option value=''>請選擇{$now_seme}班級</option>
            $opt
          </select>
        </td>
      </tr>
      <tr>
        <th>學習收藏內容</th>
        <td colspan=3><textarea name='content' cols=50 rows=8></textarea></td>
      </tr>
      <tr>
        <th>設定密碼:</th>
        <td><input type='text' name='text_passwd' size='10'></td>
        <th>是否發布?</th>
        <td>
          <input type='radio' name='enable' value='1' id='enable'><label for='enable'>發布</label>
          <input type='radio' name='enable' value='0' id='unable'><label for='unable'>暫不發布</label>
          <input type='hidden' name='op' value='insert_article'>
          <input type='submit' value='儲存'>
        </td>
      </tr>
    </table>
  </form>
  ";
  return $main;
}


//執行儲存動作
function insert_article(){
  $sql="INSERT INTO `tncomu_article`(`stud_name`, `content`, `post_time`, `enable`, `class_sn`, `mode`, `text_passwd`) VALUES ('{$_POST['stud_name']}' , '{$_POST['content']}' , now(), '{$_POST['enable']}', '{$_POST['class_sn']}', '文字', '{$_POST['text_passwd']}')";
  mysql_query($sql) or die(mysql_error().$sql);
  return "儲存完畢";
}

//自動抓出目前學期
function get_seme(){
  $year=date("Y")-1911;
  $mon=date("n");
  if($mon<=2){
    $year=$year-1;
    $seme="{$year}2";
  }elseif($mon>=3 and $mon<=8){
    $seme="{$year}1";
  }else{
    $seme="{$year}2";
  }
  return $seme;
}

?>

:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D560%26tbsn%3D20

書籍目錄

展開 | 闔起

線上使用者

56人線上 (19人在瀏覽線上書籍)

會員: 0

訪客: 56

更多…