[1002] PHP入門班
<?php
//引入共同檔
require_once "header.php";
//變數初始化
$op=isset($_REQUEST['op'])?$_REQUEST['op']:"";
$class_sn=isset($_REQUEST['class_sn'])?intval($_REQUEST['class_sn']):"";
//流程控制
if($op=="update"){
update_class($class_sn);
}else{
insert_class();
}
/*************** 功能函數區 **************/
function insert_class(){
//SQL新增語法
$sql="insert into tncomu_class (`seme`, `subject`, `class_name`, `teacher`, `passwd`, `access`) values('{$_POST['seme']}' , '{$_POST['subject']}' , '{$_POST['class_name']}' , '{$_POST['teacher']}' , '{$_POST['passwd']}' , '{$_POST['access']}')";
//執行SQL語法
mysql_query($sql) or die("無法執行:".mysql_error());
//執行完轉向
header("location: index.php");
}
function update_class($class_sn=""){
//SQL更新語法
$sql="update tncomu_class set `seme`='{$_POST['seme']}', `subject`='{$_POST['subject']}', `class_name`='{$_POST['class_name']}', `teacher`='{$_POST['teacher']}', `passwd`='{$_POST['passwd']}', `access`='{$_POST['access']}' where class_sn='$class_sn'";
//執行SQL語法
mysql_query($sql) or die("無法執行:".mysql_error());
//執行完轉向
header("location: index.php");
}
?>