#表單 case "op_form": op_form($sn); break;
這裡仍然使用 op_form($sn=""),但程式須修改
#抓取預設值 if($sn) { #編輯 $DBV=get_show_kind($sn);//取得單筆記錄 $DBV['op'] = "op_update"; $DBV['form_title'] = "編輯選單"; }else { #新增 $DBV=array(); $DBV['op'] = "op_insert"; $DBV['form_title'] = "新增選單"; }
取得單筆記錄
######################################## #取得單筆記錄 ######################################## function get_show_kind($sn="") { global $mysqli; if(!$sn)redirect_header("index.php",3000,"查詢選單資料錯誤!!"); $sql = "select * from `show_kind` where `sn`='{$sn}' and `kind`='nav_home'"; //$mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); $result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); $DBV = $result->fetch_assoc(); #過濾撈出資料 $DBV['sn'] = intval($DBV['sn']); //http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp $DBV['title'] = htmlspecialchars($DBV['title'], ENT_QUOTES); // 轉換雙引號和單引號 $DBV['url'] = htmlspecialchars($DBV['url'], ENT_QUOTES); // 轉換雙引號和單引號 $DBV['sort'] = intval($DBV['sort']); $DBV['enable'] = intval($DBV['enable']); $DBV['target'] = intval($DBV['target']); return $DBV; }
和新增表單相同,故不用處理