Title1

Title2

Title3

11-5 新增記錄

一、流程


  #新增記錄
  case "op_insert":
    op_insert();
    redirect_header("index.php",3000,"新增資料成功!!");
  break;

二、函數

########################################
# 新增記錄
########################################
function op_insert()
{
  global $mysqli;
  #資料過濾
  #http://php.net/manual/en/mysqli.real-escape-string.php
  $_POST['title']  = $mysqli->real_escape_string($_POST['title']);
  $_POST['target'] = intval($_POST['target']);
  $_POST['enable'] = intval($_POST['enable']);
  $_POST['sort']   = intval($_POST['sort']);
  $_POST['url']    = $mysqli->real_escape_string($_POST['url']);

  # nav_home => 首頁的選單
  $_POST['kind'] = "nav_home";

  $sql = "insert into `show_kind`
          (`title`, `target`, `enable`, `sort`,`url`,`kind`)
          VALUES
          ('{$_POST['title']}', '{$_POST['target']}', '{$_POST['enable']}', '{$_POST['sort']}', '{$_POST['url']}', '{$_POST['kind']}')";
  $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate));

  $sn=$mysqli->insert_id;//傳回insert 指令所產生之流水號

  return $sn;
}