內容選單標籤

2017年8月9日 星期三

dreamweaver CS6 + PHP









------------------------------------------------------------------下載安裝appserv-win32-8.6.0


http://127.0.0.1/   >phpMyAdmin Database Manager Version 4.6.6   >使用者名稱:root   >密碼:db123456


資料庫   >建立新資料庫:kkdb   >utf8_unicode_ci   >建立

建立資料表   >名稱:建立資料表   >欄:4   >執行


名稱   型態                 長度值   ...   屬性                       索引                  A_I
mid     INT
na       VARCHAR       20                 UNSIGNED           PRIMARY       V
acnt    VARCHAR       10
pwd    VARCHAR       10


>儲存

新增2筆資料









------------------------------------------------------------------安裝CS6測試版

Dreamweaver 新增網站

1. 網站   -->網站名稱:kkweb01   -->本機網站資料夾:C:\AppServ\www\kkweb01\

2. 伺服器

   伺服器   -->新增伺服器

   基本   -->伺服器名稱:localhost   -->連線方式:本機網路   -->伺服器資料夾:    C:\AppServ\www\kkweb01   -->WEB URL:http://127.0.0.1/kkweb01/

   進階   -->伺服器模式:PHP MYSQL

   儲存   -->勾選  測試

3. 進階設定:
本地資訊:預設影像資料夾   -->C:\AppServ\www\kkweb01\images   -->儲存




4. 視窗   -->工作區面板   -->傳統

5. 檔案   -->於瀏覽器中預覽   -->編輯瀏覽器清單   -->在瀏覽器中預覽   -->chrome   -->主要瀏覽器   -->確定

6.檢視   -->工具列   -->標準








------------------------------------------------------------------list.php

視窗   >資料庫   >MySQL連線   >conn01   >localhost   >root   >db123456   >選取   >kkdb   >確定   >測試   >確定


視窗   >繫結   >資料集(查詢)   >Rs1   >conn01   >tblmen   >全選   >確定   >資料集(Rs1) 欄位 拖曳至表格相對欄位   >選取表格資料呈現列   >伺服器行為   >重複區域   >所有紀錄   >確定   >F12預覽


code:

<?php require_once('Connections/conn01.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;  
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_conn01, $conn01);
$query_Rs1 = "SELECT * FROM tblmen";
$Rs1 = mysql_query($query_Rs1, $conn01) or die(mysql_error());
$row_Rs1 = mysql_fetch_assoc($Rs1);
$totalRows_Rs1 = mysql_num_rows($Rs1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="500" border="1" align="center">
    <tr>
      <td colspan="6" align="center"><strong>瀏覽資料</strong></td>
    </tr>
    <tr>
      <td>編號</td>
      <td>姓名</td>
      <td>帳號</td>
      <td>密碼</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <?php do { ?>
      <tr>
        <td><?php echo $row_Rs1['mid']; ?></td>
        <td><?php echo $row_Rs1['na']; ?></td>
        <td><?php echo $row_Rs1['acnt']; ?></td>
        <td><?php echo $row_Rs1['pwd']; ?></td>
        <td>修改</td>
        <td>刪除</td>
      </tr>
      <?php } while ($row_Rs1 = mysql_fetch_assoc($Rs1)); ?>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><a href="add.php">新增資料</a></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>
<?php
mysql_free_result($Rs1);
?>




------------------------------------------------------------------add.php

視窗   >伺服器行為   >插入資料   >插入後請前往:list.php   >確定

設定 list.php 內 新增資料 文字 超連結


code:
<?php require_once('Connections/conn01.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;  
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO tblmen (na, acnt, pwd) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['na'], "text"),
                       GetSQLValueString($_POST['acnt'], "text"),
                       GetSQLValueString($_POST['pwd'], "text"));

  mysql_select_db($database_conn01, $conn01);
  $Result1 = mysql_query($insertSQL, $conn01) or die(mysql_error());

  $insertGoTo = "list.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="500" border="0" align="center">
    <tr>
      <td colspan="3" align="center"><strong>新增資料</strong></td>
    </tr>
    <tr>
      <td>姓名</td>
      <td colspan="2"><input type="text" name="na" id="na" /></td>
    </tr>
    <tr>
      <td>帳號</td>
      <td colspan="2"><input type="text" name="acnt" id="acnt" /></td>
    </tr>
    <tr>
      <td>密碼</td>
      <td colspan="2"><input type="text" name="pwd" id="pwd" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="cancel" id="cancel" value="取消" /></td>
      <td><input type="submit" name="ok" id="ok" value="新增" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="2">&nbsp;</td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>





------------------------------------------------------------------upd.php

1. 複製 add.php 為 upd.php
2. 加入一個隱藏欄位 id=mid name=mid
3. 刪除
    視窗   >伺服器行為   >插入資料

設定 list.php 內 修改 文字 超連結
參數   >mid   > <?php echo $row_Rs1['mid']; ?>   >確定   >URL:upd.php?mid=<?php echo $row_Rs1['mid']; ?>   >確定


upd.php

視窗   >繫結   >資料集(查詢)   >Rs1   >conn01   >tblmen   >全選   >篩選器 mid   >=   >URL參數   >mid   >確定   >資料集(Rs1) 欄位 拖曳至表格相對欄位,包含 隱藏欄位 id=mid


視窗   >伺服器行為   >更新紀錄   >form1   >conn01   >tblmen   >值:FORM.mid   >送出為:整數   >勾選 主索引鍵   >更新後,請前往:list.php   >確定



code:

<?php require_once('Connections/conn01.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;  
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE tblmen SET na=%s, acnt=%s, pwd=%s WHERE mid=%s",
                       GetSQLValueString($_POST['na'], "text"),
                       GetSQLValueString($_POST['acnt'], "text"),
                       GetSQLValueString($_POST['pwd'], "text"),
                       GetSQLValueString($_POST['mid'], "int"));

  mysql_select_db($database_conn01, $conn01);
  $Result1 = mysql_query($updateSQL, $conn01) or die(mysql_error());

  $updateGoTo = "list.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_Rs1 = "-1";
if (isset($_GET['mid'])) {
  $colname_Rs1 = $_GET['mid'];
}
mysql_select_db($database_conn01, $conn01);
$query_Rs1 = sprintf("SELECT * FROM tblmen WHERE mid = %s", GetSQLValueString($colname_Rs1, "int"));
$Rs1 = mysql_query($query_Rs1, $conn01) or die(mysql_error());
$row_Rs1 = mysql_fetch_assoc($Rs1);
$totalRows_Rs1 = mysql_num_rows($Rs1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
  <table width="500" border="0" align="center">
    <tr>
      <td colspan="3" align="center"><strong>修改資料</strong></td>
    </tr>
    <tr>
      <td>姓名</td>
      <td colspan="2"><input name="na" type="text" id="na" value="<?php echo $row_Rs1['na']; ?>" /></td>
    </tr>
    <tr>
      <td>帳號</td>
      <td colspan="2"><input name="acnt" type="text" id="acnt" value="<?php echo $row_Rs1['acnt']; ?>" /></td>
    </tr>
    <tr>
      <td>密碼</td>
      <td colspan="2"><input name="pwd" type="text" id="pwd" value="<?php echo $row_Rs1['pwd']; ?>" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="2"><input name="mid" type="hidden" id="mid" value="<?php echo $row_Rs1['mid']; ?>" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="cancel" id="cancel" value="取消" /></td>
      <td><input type="submit" name="ok" id="ok" value="修改" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1" />
</form>
</body>
</html>
<?php
mysql_free_result($Rs1);
?>


------------------------------------------------------------------刪除資料功能,整合在 list.php 內

設定 list.php 內 文字  "刪除" 超連結
檔案名稱:list.php   >參數   >

名稱      值
mid        <?php echo $row_Rs1['mid']; ?>
isDel      yes

>確定

URL:    ./?mid=<?php echo $row_Rs1['mid']; ?>&isDel=yes

>確定


視窗   >伺服器行為   >刪除紀錄   >
主索引鍵   >conn01   >tblmen   >主索引鍵欄位:mid   >勾選   數值
                                                    >主索引鍵:URL 參數   >mid
                                                    >確定


//修改程式碼
//先判斷只有在 isDel 成立,才進行刪除動作

if ((isset($_GET['isDel'])) && ($_GET['isDel'] != "")) {

if ((isset($_GET['mid'])) && ($_GET['mid'] != "")) {
 $deleteSQL = sprintf("DELETE FROM tblmen WHERE mid=%s",
  GetSQLValueString($_GET['mid'], "int"));

 mysql_select_db($database_conn01, $conn01);
 $Result1 = mysql_query($deleteSQL, $conn01) or die(mysql_error());
}

}








code:

<?php require_once('Connections/conn01.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;  
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

if ((isset($_GET['isDel'])) && ($_GET['isDel'] != "")) {
if ((isset($_GET['mid'])) && ($_GET['mid'] != "")) {
 $deleteSQL = sprintf("DELETE FROM tblmen WHERE mid=%s",
  GetSQLValueString($_GET['mid'], "int"));

 mysql_select_db($database_conn01, $conn01);
 $Result1 = mysql_query($deleteSQL, $conn01) or die(mysql_error());
}
}
mysql_select_db($database_conn01, $conn01);
$query_Rs1 = "SELECT * FROM tblmen";
$Rs1 = mysql_query($query_Rs1, $conn01) or die(mysql_error());
$row_Rs1 = mysql_fetch_assoc($Rs1);
$totalRows_Rs1 = mysql_num_rows($Rs1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="500" border="1" align="center">
    <tr>
      <td colspan="6" align="center"><strong>瀏覽資料</strong></td>
    </tr>
    <tr>
      <td>編號</td>
      <td>姓名</td>
      <td>帳號</td>
      <td>密碼</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <?php do { ?>
      <tr>
        <td><?php echo $row_Rs1['mid']; ?></td>
        <td><?php echo $row_Rs1['na']; ?></td>
        <td><?php echo $row_Rs1['acnt']; ?></td>
        <td><?php echo $row_Rs1['pwd']; ?></td>
        <td><a href="upd.php?mid=<?php echo $row_Rs1['mid']; ?>">修改</a></td>
        <td><a href="list.php?mid=<?php echo $row_Rs1['mid']; ?>&amp;isDel=yes">刪除</a></td>
      </tr>
      <?php } while ($row_Rs1 = mysql_fetch_assoc($Rs1)); ?>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><a href="add.php">新增資料</a></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>
<?php
mysql_free_result($Rs1);
?>





------------------------------------------------------------------index.php 使用者驗證



視窗   >伺服器行為   >使用者驗證   >登入使用者

輸入來源表單:               form1
使用者名稱欄位:           acnt
密碼欄位:                       pwd
---------------------------------------
使用連線驗證:              conn01
表格:                              tblmen  
使用者名稱欄:              acnt
密碼欄:                          pwd
---------------------------------------
如果登入成功,即前往:list.php
如果登入失敗,即前往:list.php
---------------------------------------
限制存取準則:

>確定





code:

<?php require_once('Connections/conn01.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;  
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['acnt'])) {
  $loginUsername=$_POST['acnt'];
  $password=$_POST['pwd'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "list.php";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_conn01, $conn01);

  $LoginRS__query=sprintf("SELECT acnt, pwd FROM tblmen WHERE acnt=%s AND pwd=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
 
  $LoginRS = mysql_query($LoginRS__query, $conn01) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
 
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;    

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  <table width="300" border="1" align="center">
    <tr>
      <td colspan="2" align="center">使用者登入</td>
    </tr>

    <tr>
      <td>帳號</td>
      <td><input type="text" name="acnt" id="acnt" /></td>
    </tr>
    <tr>
      <td>密碼</td>
      <td><input type="text" name="pwd" id="pwd" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="login" id="login" value="登入" /></td>
    </tr>
  </table>
</form>
</body>
</html>