<a href="main.php?op=edit&sn=<{$sn}>" class="btn btn-mini btn-warning">編輯</a>
case "edit": add_form($sn); break;
//編輯詞彙表單 function add_form($sn=""){ global $xoopsTpl,$xoopsDB; include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php"); if($sn){ $sql="select eng,cht from ".$xoopsDB->prefix("oxford")." where `sn`='{$sn}'"; $result=$xoopsDB->queryF($sql) or redirect_header('index.php', 3, mysql_error()); list($eng,$cht)=$xoopsDB->fetchRow($result); $op="update"; }else{ $op="insert"; } $form = new XoopsThemeForm('編輯詞彙', '', 'main.php', 'post', true); $input_eng =new XoopsFormText('英文', 'eng', 20 , 255 , $eng); $input_cht =new XoopsFormText('中文解釋', 'cht', 20 , 255 , $cht); $hidden_op =new XoopsFormHidden('op', $op); $hidden_sn =new XoopsFormHidden('sn', $sn); $submit_btn =new XoopsFormButton('', '', '儲存', 'submit'); $form->addElement($input_eng); $form->addElement($input_cht); $form->addElement($hidden_op); $form->addElement($hidden_sn); $form->addElement($submit_btn); $f=$form->render(); $xoopsTpl->assign("form" ,$f); }
case "update": update($sn); break; header("location:../index.php?eng={$_POST['eng']}");
//更新詞彙 function update($sn=""){ global $xoopsDB; $eng=$_POST['eng']; $cht=$_POST['cht']; $sql="update `".$xoopsDB->prefix('oxford')."` set `eng`='{$eng}' , `cht`='{$cht}' where sn='$sn'"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); }