Title1

Title2

Title3

9-2 上課範例

admin_prod.php
 

###############################
# 預設
###############################
function opForm($sn=""){
global $db,$smarty;
/*
`sn` int(10) unsigned NOT NULL auto_increment comment 'prod_sn',
`kind` smallint(5) unsigned NOT NULL default 0 comment '分類',
`title` varchar(255) NOT NULL default '' comment '名稱',
`summary` text NULL comment '摘要',
`content` text NULL comment '內容',
`price` int(10) unsigned NOT NULL comment '價格',
`amount` int(10) unsigned NOT NULL comment '數量',
`enable` enum('1','0') NOT NULL default '1' comment '狀態',
`choice` enum('1','0') NOT NULL default '0' comment '精選',
`date` int(10) unsigned NOT NULL default 0 comment '建立日期',
`sort` smallint(5) unsigned NOT NULL default 0 comment '排序',
`counter` int(10) unsigned NOT NULL default 0 comment '人氣',
`icon` varchar(255) NOT NULL default ''  comment '圖示',
*/
if($sn){
#編輯
}else{
#新增
$row =array();
}
$row['sn'] = isset($row['sn']) ? $row['sn']: "";
$row['kind'] = isset($row['kind']) ? $row['kind']: "";
$row['title'] = isset($row['title']) ? $row['title']: "";
$row['summary'] = isset($row['summary']) ? $row['summary']: "";
$row['content'] = isset($row['content']) ? $row['content']: "";
$row['price'] = isset($row['price']) ? $row['price']: 0;
$row['amount'] = isset($row['amount']) ? $row['amount']: 0;
$row['enable'] = isset($row['enable']) ? $row['enable']: "1";
$row['choice'] = isset($row['choice']) ? $row['choice']: "0";
$row['date'] = isset($row['date']) ? $row['date']: 0;
$row['sort'] = isset($row['sort']) ? $row['sort']: 0;
$row['icon'] = isset($row['icon']) ? $row['icon']: "";
$smarty->assign("row", $row);
$token = getTokenHTML();
$smarty->assign("token", $token);
}

admin_prod.tpl

<{if $op == "opForm"}>
<div class="panel panel-primary">
<div class="panel-heading">商品管理</div>
<div class="panel-body"> 
<form action="admin_prod.php" method="POST" role="form" id="opForm" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<label for="title">商品名稱</label>
<input type="text" class="form-control" id="title" name="title" value="<{$row.title}>">
</div>        		
</div>
<div class="col-sm-3">
<div class="form-group">
<label for="kind">商品類別</label>
<input type="text" class="form-control" id="kind" name="kind" value="<{$row.kind}>">
</div>        		
</div>
</div>
<{$token}>
<button type="submit" class="btn btn-primary btn-block">送出</button>
<input type="hidden" value="opUpdate" name="op">
<input type="hidden" value="<{$row.sn}>" name="sn" id="sn">
</form>
</div>
</div>
<{/if}>

https://drive.google.com/file/d/16msPPtk0WSH9q_ckznJhzLgCCe_BpbKx/view?usp=sharing