刪除 ``` 2. 加入修改連結,並流程新增一組 case "modify": ``` 編輯 ``` ### 二、 刪除 1. 在進入流程前,整理一下傳入變數: ``` $honor_sn = isset($_REQUEST['honor_sn']) ? intval($_REQUEST['honor_sn']) : ""; ``` 2. 刪除函數: ``` function del_honor($honor_sn=""){ global $xoopsDB; $sql="delete from ".$xoopsDB->prefix("tad_honor")." where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ``` ### 三、確認後刪除 1. 先加入javascript的刪除函數 ``` ``` 2. 把連結改為執行javascript ``` 刪除 ``` ### 四、 完成修改功能 1. 修改功能就是使用者選擇一筆資料(取得該資料編號),利用該資料編號,取得其原始資料,並將取得的資料塞回原先表單,以供使用者修改。改完送出後,會執行資料update的動作。 2. 在switch中新增一組modify 流程: ``` 編輯 ``` 3. 替原本的表單函數加入參數:function honor\_form($honor\_sn=null) ``` case "modify_honor": $main = honor_form($honor_sn); break; ``` 4. 根據 $honor\_sn 來取得原始輸入的資料: ``` //抓出原始資料 if($honor_sn){ $sql="select * from ".$xoopsDB->prefix("tad_honor")." where `honor_sn` = '$honor_sn'"; $result = $xoopsDB->query($sql) or redirect_header('main.php', 3, mysql_error()); $myts =& MyTextSanitizer::getInstance(); $all = $xoopsDB->fetchArray($result); } ``` 5. 把預設值塞進XOOPS表單元件中: ``` $XoopsFormText =new XoopsFormText('得獎者', 'honor_student', 40 , 255, $all['honor_students']); ``` 6. 根據情況,自動修改表單的op值,以便進行不同的動作: ``` //設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
編輯 ``` ### 二、 刪除 1. 在進入流程前,整理一下傳入變數: ``` $honor_sn = isset($_REQUEST['honor_sn']) ? intval($_REQUEST['honor_sn']) : ""; ``` 2. 刪除函數: ``` function del_honor($honor_sn=""){ global $xoopsDB; $sql="delete from ".$xoopsDB->prefix("tad_honor")." where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ``` ### 三、確認後刪除 1. 先加入javascript的刪除函數 ``` ``` 2. 把連結改為執行javascript ``` 刪除 ``` ### 四、 完成修改功能 1. 修改功能就是使用者選擇一筆資料(取得該資料編號),利用該資料編號,取得其原始資料,並將取得的資料塞回原先表單,以供使用者修改。改完送出後,會執行資料update的動作。 2. 在switch中新增一組modify 流程: ``` 編輯 ``` 3. 替原本的表單函數加入參數:function honor\_form($honor\_sn=null) ``` case "modify_honor": $main = honor_form($honor_sn); break; ``` 4. 根據 $honor\_sn 來取得原始輸入的資料: ``` //抓出原始資料 if($honor_sn){ $sql="select * from ".$xoopsDB->prefix("tad_honor")." where `honor_sn` = '$honor_sn'"; $result = $xoopsDB->query($sql) or redirect_header('main.php', 3, mysql_error()); $myts =& MyTextSanitizer::getInstance(); $all = $xoopsDB->fetchArray($result); } ``` 5. 把預設值塞進XOOPS表單元件中: ``` $XoopsFormText =new XoopsFormText('得獎者', 'honor_student', 40 , 255, $all['honor_students']); ``` 6. 根據情況,自動修改表單的op值,以便進行不同的動作: ``` //設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
$honor_sn = isset($_REQUEST['honor_sn']) ? intval($_REQUEST['honor_sn']) : ""; ``` 2. 刪除函數: ``` function del_honor($honor_sn=""){ global $xoopsDB; $sql="delete from ".$xoopsDB->prefix("tad_honor")." where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ``` ### 三、確認後刪除 1. 先加入javascript的刪除函數 ``` ``` 2. 把連結改為執行javascript ``` 刪除 ``` ### 四、 完成修改功能 1. 修改功能就是使用者選擇一筆資料(取得該資料編號),利用該資料編號,取得其原始資料,並將取得的資料塞回原先表單,以供使用者修改。改完送出後,會執行資料update的動作。 2. 在switch中新增一組modify 流程: ``` 編輯 ``` 3. 替原本的表單函數加入參數:function honor\_form($honor\_sn=null) ``` case "modify_honor": $main = honor_form($honor_sn); break; ``` 4. 根據 $honor\_sn 來取得原始輸入的資料: ``` //抓出原始資料 if($honor_sn){ $sql="select * from ".$xoopsDB->prefix("tad_honor")." where `honor_sn` = '$honor_sn'"; $result = $xoopsDB->query($sql) or redirect_header('main.php', 3, mysql_error()); $myts =& MyTextSanitizer::getInstance(); $all = $xoopsDB->fetchArray($result); } ``` 5. 把預設值塞進XOOPS表單元件中: ``` $XoopsFormText =new XoopsFormText('得獎者', 'honor_student', 40 , 255, $all['honor_students']); ``` 6. 根據情況,自動修改表單的op值,以便進行不同的動作: ``` //設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
function del_honor($honor_sn=""){ global $xoopsDB; $sql="delete from ".$xoopsDB->prefix("tad_honor")." where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ``` ### 三、確認後刪除 1. 先加入javascript的刪除函數 ``` ``` 2. 把連結改為執行javascript ``` 刪除 ``` ### 四、 完成修改功能 1. 修改功能就是使用者選擇一筆資料(取得該資料編號),利用該資料編號,取得其原始資料,並將取得的資料塞回原先表單,以供使用者修改。改完送出後,會執行資料update的動作。 2. 在switch中新增一組modify 流程: ``` 編輯 ``` 3. 替原本的表單函數加入參數:function honor\_form($honor\_sn=null) ``` case "modify_honor": $main = honor_form($honor_sn); break; ``` 4. 根據 $honor\_sn 來取得原始輸入的資料: ``` //抓出原始資料 if($honor_sn){ $sql="select * from ".$xoopsDB->prefix("tad_honor")." where `honor_sn` = '$honor_sn'"; $result = $xoopsDB->query($sql) or redirect_header('main.php', 3, mysql_error()); $myts =& MyTextSanitizer::getInstance(); $all = $xoopsDB->fetchArray($result); } ``` 5. 把預設值塞進XOOPS表單元件中: ``` $XoopsFormText =new XoopsFormText('得獎者', 'honor_student', 40 , 255, $all['honor_students']); ``` 6. 根據情況,自動修改表單的op值,以便進行不同的動作: ``` //設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
``` 2. 把連結改為執行javascript ``` 刪除 ``` ### 四、 完成修改功能 1. 修改功能就是使用者選擇一筆資料(取得該資料編號),利用該資料編號,取得其原始資料,並將取得的資料塞回原先表單,以供使用者修改。改完送出後,會執行資料update的動作。 2. 在switch中新增一組modify 流程: ``` 編輯 ``` 3. 替原本的表單函數加入參數:function honor\_form($honor\_sn=null) ``` case "modify_honor": $main = honor_form($honor_sn); break; ``` 4. 根據 $honor\_sn 來取得原始輸入的資料: ``` //抓出原始資料 if($honor_sn){ $sql="select * from ".$xoopsDB->prefix("tad_honor")." where `honor_sn` = '$honor_sn'"; $result = $xoopsDB->query($sql) or redirect_header('main.php', 3, mysql_error()); $myts =& MyTextSanitizer::getInstance(); $all = $xoopsDB->fetchArray($result); } ``` 5. 把預設值塞進XOOPS表單元件中: ``` $XoopsFormText =new XoopsFormText('得獎者', 'honor_student', 40 , 255, $all['honor_students']); ``` 6. 根據情況,自動修改表單的op值,以便進行不同的動作: ``` //設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
刪除 ``` ### 四、 完成修改功能 1. 修改功能就是使用者選擇一筆資料(取得該資料編號),利用該資料編號,取得其原始資料,並將取得的資料塞回原先表單,以供使用者修改。改完送出後,會執行資料update的動作。 2. 在switch中新增一組modify 流程: ``` 編輯 ``` 3. 替原本的表單函數加入參數:function honor\_form($honor\_sn=null) ``` case "modify_honor": $main = honor_form($honor_sn); break; ``` 4. 根據 $honor\_sn 來取得原始輸入的資料: ``` //抓出原始資料 if($honor_sn){ $sql="select * from ".$xoopsDB->prefix("tad_honor")." where `honor_sn` = '$honor_sn'"; $result = $xoopsDB->query($sql) or redirect_header('main.php', 3, mysql_error()); $myts =& MyTextSanitizer::getInstance(); $all = $xoopsDB->fetchArray($result); } ``` 5. 把預設值塞進XOOPS表單元件中: ``` $XoopsFormText =new XoopsFormText('得獎者', 'honor_student', 40 , 255, $all['honor_students']); ``` 6. 根據情況,自動修改表單的op值,以便進行不同的動作: ``` //設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
編輯 ``` 3. 替原本的表單函數加入參數:function honor\_form($honor\_sn=null) ``` case "modify_honor": $main = honor_form($honor_sn); break; ``` 4. 根據 $honor\_sn 來取得原始輸入的資料: ``` //抓出原始資料 if($honor_sn){ $sql="select * from ".$xoopsDB->prefix("tad_honor")." where `honor_sn` = '$honor_sn'"; $result = $xoopsDB->query($sql) or redirect_header('main.php', 3, mysql_error()); $myts =& MyTextSanitizer::getInstance(); $all = $xoopsDB->fetchArray($result); } ``` 5. 把預設值塞進XOOPS表單元件中: ``` $XoopsFormText =new XoopsFormText('得獎者', 'honor_student', 40 , 255, $all['honor_students']); ``` 6. 根據情況,自動修改表單的op值,以便進行不同的動作: ``` //設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
case "modify_honor": $main = honor_form($honor_sn); break; ``` 4. 根據 $honor\_sn 來取得原始輸入的資料: ``` //抓出原始資料 if($honor_sn){ $sql="select * from ".$xoopsDB->prefix("tad_honor")." where `honor_sn` = '$honor_sn'"; $result = $xoopsDB->query($sql) or redirect_header('main.php', 3, mysql_error()); $myts =& MyTextSanitizer::getInstance(); $all = $xoopsDB->fetchArray($result); } ``` 5. 把預設值塞進XOOPS表單元件中: ``` $XoopsFormText =new XoopsFormText('得獎者', 'honor_student', 40 , 255, $all['honor_students']); ``` 6. 根據情況,自動修改表單的op值,以便進行不同的動作: ``` //設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
//抓出原始資料 if($honor_sn){ $sql="select * from ".$xoopsDB->prefix("tad_honor")." where `honor_sn` = '$honor_sn'"; $result = $xoopsDB->query($sql) or redirect_header('main.php', 3, mysql_error()); $myts =& MyTextSanitizer::getInstance(); $all = $xoopsDB->fetchArray($result); } ``` 5. 把預設值塞進XOOPS表單元件中: ``` $XoopsFormText =new XoopsFormText('得獎者', 'honor_student', 40 , 255, $all['honor_students']); ``` 6. 根據情況,自動修改表單的op值,以便進行不同的動作: ``` //設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
$XoopsFormText =new XoopsFormText('得獎者', 'honor_student', 40 , 255, $all['honor_students']); ``` 6. 根據情況,自動修改表單的op值,以便進行不同的動作: ``` //設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
//設定op值 if($honor_sn){ $form->addElement(new XoopsFormHidden('op', 'update_honor')); $form->addElement(new XoopsFormHidden('honor_sn', $honor_sn)); }else{ $form->addElement(new XoopsFormHidden('op', 'insert_honor')); } ``` 7. 在switch中新增一組update 流程: ``` case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
case "update_honor": update_honor($honor_sn); header("location:main.php"); break; ``` 8. 製作更新函數update\_honor($honor\_sn): ``` //更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
//更新榮譽榜資料庫 function update_honor($honor_sn=""){ global $xoopsDB; if(!$GLOBALS['xoopsSecurity']->check()){ $error=implode("" , $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'],3, $error); } //文字過濾 $myts = & MyTextSanitizer::getInstance(); $_POST['honor_year'] = $myts->addSlashes($_POST['honor_year']); $_POST['honor_date'] = $myts->addSlashes($_POST['honor_date']); $_POST['honor_students'] = $myts->addSlashes($_POST['honor_students']); $_POST['honor_descript'] = $myts->addSlashes($_POST['honor_descript']); $_POST['honor_teachers'] = $myts->addSlashes($_POST['honor_teachers']); $sql="update ".$xoopsDB->prefix("tad_honor")." set `honor_year` = '{$_POST['honor_year']}', `honor_date` = '{$_POST['honor_date']}', `honor_students` = '{$_POST['honor_students']}', `honor_descript` = '{$_POST['honor_descript']}', `honor_teachers` = '{$_POST['honor_teachers']}' where `honor_sn`='{$honor_sn}'"; $xoopsDB->queryF($sql) or redirect_header('main.php', 3, mysql_error()); } ```
進階搜尋
53人線上 (8人在瀏覽線上書籍)
會員: 0
訪客: 53