:::
7-2 更新活動
一、更新資料的SQL語法
- 更新資料的SQL語法:
update `資料表名稱` set `欄位1`='值1', `欄位2`='值2', ... [where 篩選條件] [limit 筆數]
二、加入更新功能
- 由於修改時 $op 會變成 update_action,所以,要針對此 $op 多做一組流程對應,修改 admin/main.php,編輯其中的流程:
case "update_action": update_action(); header("location: ../index.php?action_id={$action_id}"); exit; -
接著,實際做出 update_action() 函數即可。
//更新資料庫 function update_action() { global $xoopsDB, $xoopsUser; //安全判斷 if (!$GLOBALS['xoopsSecurity']->check()) { $error = implode("<br>", $GLOBALS['xoopsSecurity']->getErrors()); throw new Exception($error); } $action_id = clean_var('action_id', '活動編號'); $title = clean_var('title', '活動名稱'); $action_date = clean_var('action_date', '活動日期'); $end_date = clean_var('end_date', '截止日期'); $enable = clean_var('enable', '使否啟用'); $content = clean_var('content', '活動內容'); $uid = $xoopsUser->uid(); $sql = "UPDATE `" . $xoopsDB->prefix('actions') . "` SET `title`='{$title}', `content`='{$content}', `action_date`='{$action_date}', `end_date`='{$end_date}', `uid`='{$uid}', `enable`='{$enable}' WHERE `action_id`= '$action_id'"; $xoopsDB->query($sql) or web_error($sql); }
7-1 編輯活動