<?php
error_reporting(0);
$link=@mysql_connect("localhost" , "tad0616" ,"12345");
if(!$link) echo "資料庫連不上!";
//設定使用UTF8編碼
mysql_query("SET NAMES 'utf8'");
//選擇資料庫
mysql_select_db('tad0616');
$op=isset($_REQUEST['op'])?$_REQUEST['op']:"";
$class_sn=isset($_REQUEST['class_sn'])?intval($_REQUEST['class_sn']):"";
$next_op=($class_sn)?"update":"insert";
if($op=="edit"){
//設定SQL語法
$sql="select * from `tncomu_class` where class_sn='{$class_sn}'";
//執行SQL語法
$result=mysql_query($sql) or die("無法執行:".mysql_error());
//擷取資料回來存到 $data
$data=mysql_fetch_assoc($result);
//還原下拉選單預設值
$opt1=($data['subject']=="語言與文化")?"selected":"";
$opt2=($data['subject']=="生命與健康")?"selected":"";
$opt3=($data['subject']=="社會與生活")?"selected":"";
$opt4=($data['subject']=="自然與環境")?"selected":"";
$opt5=($data['subject']=="美學與藝術")?"selected":"";
$opt6=($data['subject']=="資訊與傳播")?"selected":"";
$opt7=($data['subject']=="台江分校")?"selected":"";
$opt8=($data['subject']=="台江大廟興學")?"selected":"";
$radio1=($data['access']=="1")?"checked":"";
$radio0=($data['access']=="0")?"checked":"";
}
$main="
<meta http-equiv='content-type' content='text/html; charset=utf-8'>
<form action='save_class.php' method='post'>
學年學期:<input type='text' name='seme' size='4' value='{$data['seme']}'><br>
所屬學程:<select name='subject' size=1>
<option value='語言與文化' $opt1>語言與文化</option>
<option value='生命與健康' $opt2>生命與健康</option>
<option value='社會與生活' $opt3>社會與生活</option>
<option value='自然與環境' $opt4>自然與環境</option>
<option value='美學與藝術' $opt5>美學與藝術</option>
<option value='資訊與傳播' $opt6>資訊與傳播</option>
<option value='台江分校' $opt7>台江分校</option>
<option value='台江大廟興學' $opt8>台江大廟興學</option>
</select>
<br>
班級名稱:<input type='text' name='class_name' size='30' value='{$data['class_name']}'><br>
講師名稱:<input type='text' name='teacher' size='10' value='{$data['teacher']}'><br>
管理密碼:<input type='text' name='passwd' size='10' value='{$data['passwd']}'><br>
是否開放:
<input type='radio' name='access' value='1' id='show' $radio1><label for='show'>開放</label>
<input type='radio' name='access' value='0' id='hide' $radio0><label for='hide'>隱藏</label>
<br>
<input type='hidden' name='op' value='{$next_op}'>
<input type='hidden' name='class_sn' value='{$class_sn}'>
<input type='submit' value='儲存'>
</form>";
echo $main;
?>