博客來網路書店查詢

書名

博客來網路書店查詢

星期二, 10月 26, 2010

PHP&MySQL--4 2010年10月課程講義預覽

PHP&MySQL--4
一、 陣列簡介
1. 陣列初始化


〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉第一個陣列〈/title〉〈/head〉
〈body〉〈?
$chinese[0] = 80;
$chinese[1] = 60;
$chinese[2] = 90;
$chinese[3] = 50;
$chinese[4] = 70;
for ($a=0; $a〈5; $a++)
echo "$chinese[$a] 〈br〉" ;
?〉〈/body〉〈/html〉



2. 請問以下陣列,網路硬碟上所提供的資料是否有缺?


〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉第一個陣列,不給予索引值編號〈/title〉〈/head〉
〈body〉〈?
$chinese[ ] = 80;
$chinese[ ] = 60;
$chinese[ ] = 90;
$chinese[ ] = 50;
$chinese[ ] = 70;
for ($a=0;$a〈5;$a++)
echo "座號".$a."同學的成績為:".$chinese[$a]."〈br〉" ;
?〉〈/body〉〈/html〉



3. 陣列可用array方式規劃,網路硬碟上所提供的資料是否有缺?

〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉以array方式建立陣列,索引值編號任意給〈/title〉〈/head〉
〈body〉〈?
$chinese=array(
1=〉80,
3=〉60,
6=〉90,
8=〉50,
9=〉70
);
for ($a=0;$a〈=10;$a++)
echo "座號".$a."同學的成績為:".$chinese[$a]."〈br〉" ;
?〉〈/body〉〈/html〉





4. 陣列可用文字做為索引,不過要如何看到全部資料?


〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉以array方式建立文字型態索引值陣列〈/title〉〈/head〉
〈body〉〈?
$a=array(
"Jan" =〉 "一月",
"Feb" =〉 "二月",
"Mar" =〉 "三月"
);
echo $a["Mar"]."〈br〉";
?〉〈/body〉〈/html〉



二、 for與foreach差別
1. 由「陣列可用array方式規劃」練習修改後比較,有何差別?

for ($a=0;$a〈=10;$a++)
echo $chinese[$a]."〈br〉" ;
foreach ($chinese as $value1)
echo $value1."〈br〉";




2. 由「陣列可用文字做為索引」練習修改,加入foreach讀取所有資料


foreach ($a as $value1)
echo $value1."〈br〉";



3. 由「陣列可用array方式規劃」練習修改,更快速顯示索引值與內容

foreach ($chinese as $key1 =〉$value1)
echo "座號".$key1."同學的成績為:".$value1."〈br〉" ;




三、 表單與Session:
1. 表單部分(1.php)


〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉表單登入〈/title〉〈/head〉〈body〉
〈form name="form1" method="post" action="2.php"〉請輸入姓名:
〈input type="text" name="username" maxlength="6" size="8"〉〈br〉
請輸入密碼:
〈input type="password" name="passwd" maxlength=”6” size="8"〉〈br〉
〈input type="submit"〉〈input type="reset"〉〈/form〉 〈/body〉〈/html〉



2. 接收表單資料

〈? session_start( ); ?〉〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉驗證表單資料〈/title〉〈/head〉〈body〉 〈?
if(!isset($_POST['username']))
{
?〉
〈script〉
window.alert('請輸入帳號');
//history.back( );
location.href="http://localhost/class3/session/1.php";
〈/script〉〈?
}
if(!isset($_POST['passwd']))
{
?〉
〈script〉
window.alert('請輸入密碼');
//history.back( );
location.href="http://localhost/class3/session/1.php";
〈/script〉
〈?
}
if($_POST['username']=="")
{ ?〉
〈script〉
window.alert('請輸入帳號');
history.back( );
//location.href="http://localhost/class3/session/1.php";
〈/script〉〈?
}
if($_POST['passwd']=="")
{
?〉
〈script〉
window.alert('請輸入密碼');
history.back( );
//location.href="http://localhost/class3/session/1.php";
〈/script〉
〈?
}
$_SESSION['username']=$_POST['username'];
$_SESSION['passwd']=$_POST['passwd'];
echo '〈br/〉〈a href="3.php"〉第三頁〈/a〉';
?〉〈/body〉〈/html〉
3. 第三頁的連結
〈? session_start( ); ?〉〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉查閱資料〈/title〉〈/head〉〈body〉 〈?
if(!isset($_SESSION['username']))
{
?〉
〈script〉
window.alert('請輸入帳號');
location.href='./1.php';
〈/script〉
〈?
}
if(!isset($_SESSION['passwd']))
{
?〉
〈script〉
window.alert('請輸入密碼');
location.href='./1.php';
〈/script〉
〈?
}
echo '歡迎光臨';
echo '〈br/〉〈a href="4.php"〉登出〈/a〉';
?〉〈/body〉〈/html〉



4. 第四頁登出


〈? session_start( ); ?〉〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉登出〈/title〉〈/head〉〈body〉 〈?
session_unset( );
session_destroy( );
?〉
〈script〉
//window.alert('請輸入帳號');
location.href='./1.php';
〈/script〉
〈/body〉〈/html〉



四、 修改:當網頁關閉時強制刪除session資料

〈title〉查閱資料〈/title〉〈/head〉〈body onUnLoad="checkunload();"〉
〈script〉
function checkunload()
{
location.href="./4.php";
}
〈/script〉




五、 header運用—轉移網頁
〈? header("Location: http://www.google.com"); ?〉
Q1:如果此例的utf-8含有BOM,執行時會如何呢?
Q2:如果網頁上還有其他資訊顯示,網頁可以轉移嗎?

〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉轉換網址〈/title〉〈/head〉
〈body〉〈?
header("Location: http://www.google.com");
?〉
?〉〈/body〉〈/html〉





六、 以下幾種函數都必須放在第一行,
且之前不能有任何輸出,包含空白:
header( )、setcookie( )、session_start( )、ob_start( )
七、 header運用—驗證身份後做網頁轉換【提供表單網頁】


〈? ob_start( ) ;?〉
〈html〉〈head〉〈meta http-equiv="content-type" content="text/html;charset=utf-8"〉
〈title〉驗證帳號與密碼〈/title〉〈/head〉
〈body〉〈?
if (($_POST['username']=='php') and ($_POST['passwd']=='mysql'))
header("Location: success.php");
else header("Location: failed.php");
?〉〈/body〉〈/html〉






八、 header運用—網頁每隔20秒向server讀取資料



〈? ob_start( ) ;?〉
〈html〉〈head〉〈meta http-equiv="content-type" content="text/html;charset=utf-8"〉
〈title〉網頁每隔20秒向server讀取資料〈/title〉〈/head〉
〈body〉〈?
header("refresh:20");
echo "現在時間:".date("h:i:s");
?〉〈/body〉〈/html〉



九、 header運用—網頁5秒後將轉移至google



〈? ob_start() ;?〉
〈html〉〈head〉〈meta http-equiv="content-type" content="text/html;charset=utf-8"〉
〈title〉網頁5秒後將轉移至google〈/title〉〈/head〉
〈body〉〈?
header('refresh:5; url="http://www.google.com"');
echo "五秒後連結google";
?〉〈/body〉〈/html〉




十、 與搜尋引擎有關:robots.txt


user-agent: *
disallow: /cig-bin
disallow:/members/data
disallow:/*.pdf$
十一、 如果欲禁止google抓取jpg圖片:robots.txt
user-agent: Googlebot-image
disallow:/*.jpg$




十二、 關於include

〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉foreach與print_r〈/title〉〈/head〉
〈body〉
〈TABLE align=center border=1 width=80%〉
〈TR〉〈TD〉〈? include("menu.php"); ?〉〈/TD〉
〈TD〉〈P〉這裡請輸入你的內容〈/TD〉〈/TR〉
〈/TABLE〉
〈/body〉〈/html〉





若改為require會有怎樣的情況發生呢?
若將menu.php刪除 會有怎樣的反應呢?
如果不想顯示錯誤訊息,該如何處理呢?
〈TABLE align=center border=1 width=80%〉
〈TR〉〈TD〉〈? if (!@include("menu.php")) die("連結錯誤"); ?〉〈/TD〉
〈TD〉〈P〉這裡請輸入你的內容〈/TD〉〈/TR〉
〈/TABLE〉〈/body〉〈/html〉
十三、 資料庫是什麼?
十四、 若忘記root密碼:【請參考網路硬碟提供的指令依序進行密碼設定】
十五、 一些MySQL指令
說明 指令
顯示目前資料庫 show databases;
檢視資料表:例如檢視mysql資料庫內的資料表 【請先使用資料庫】 show tables from mysql;
顯示資料表 【請先使用資料庫】 show tables;
檢視欄位 【請先使用資料庫】 show columns from db from mysql;
建立資料庫 create database pcschooldb;
刪除資料庫 drop database pcschooldb;
使用資料庫 use test;
十六、 資料庫設計
十七、 什麼是SQL檔案
十八、 利用phpMyAdmin建pcschool資料庫,將student_create_table.sql匯入
十九、 將student.sql匯入,請觀察匯入的結果。【student.sql檔案為big5編碼】
二十、 利用phpMyAdmin建立pcschool2資料庫,但校對請選擇「Big5」,並請您將student.sql匯入,請觀察匯入的結果。【student.sql檔案為big5編碼】
二十一、 談資料表索引
二十二、 其他

星期四, 10月 21, 2010

PHP&MySQL--3 2010年10月課程講義預覽

PHP&MySQL--3
一、 參考書籍:上奇出版的「PHP 6 與MySQL基礎學習教室」
二、 php5的時間調整:date.timezone -〉 Asia/Tokyo或Asia/Taipei
三、 session時間的初始化

〈? //ob_start( );
session_start( ); //啟動 session
ini_set('date.timezone','Asia/Tokyo');
?〉



備註:session暫存路徑修改 ini_set('session.save_path','../');
四、 session的生命週期


〈? session_start( ); ?〉〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉 session的生命週期〈/title〉〈/head〉〈body〉
〈?
echo "a:".$_SESSION['a']."〈br〉";
echo session_id( )."〈br〉";
$_SESSION['a']=5;
echo "a:".$_SESSION['a']."〈br〉";
echo session_id( )."〈br〉";
session_unset( );
echo "a:".$_SESSION['a']."〈br〉";
echo session_id( )."〈br〉";
session_destroy( );
echo "a:".$_SESSION['a']."〈br〉";
echo session_id( )."〈br〉";
?〉 〈a href="session_test2.php"〉session是否可以看見?〈/a〉〈/body〉〈/html〉



說明:變數註冊為session變數與反註冊session變數於PHP6內取消
請檢視若只有執行或執行,第二頁的session變數是否可以顯示內容?

〈? session_start( ); ?〉
〈head〉〈meta http-equiv="Content-Type" content="text/html; charset=utf-8" /〉
〈title〉無標題文件〈/title〉〈/head〉
〈body〉〈? echo "a:".$_SESSION['a']."〈br〉"; ?〉〈/body〉〈/html〉





五、 單一變數的清除與刪除( session_test3.php)

〈?session_start( ); ?〉〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉判斷session類型變數是否存在〈/title〉〈/head〉
〈body〉〈?
if (isset($_SESSION['b']))
{
echo "b存在"."〈br〉";
echo $_SESSION['b']."〈br〉";
}
else
{
echo "b不存在"."〈br〉";
$_SESSION['b']=50;
echo $_SESSION['b']."〈br〉";
}
?〉
〈a href="session_test4.php"〉session是否可以看見?〈/a〉〈/body〉〈/html〉






session_test4.php


〈? session_start( ); ?〉
〈head〉〈meta http-equiv="Content-Type" content="text/html; charset=utf-8" /〉
〈title〉變數清除與刪除〈/title〉〈/head〉〈body〉
〈?
echo "1b:".$_SESSION['b']."〈br〉";
//$_SESSION['b']="";
unset($_SESSION['b']);
echo "2b:".$_SESSION['b']."〈br〉";
?〉〈a href="session_test3.php"〉返回 〈/a〉〈/body〉〈/html〉




六、 網頁人數統計,加上session限制

〈?ob_start( );?〉
〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉session只能使用一次〈/title〉〈/head〉〈body〉
〈?
session_start( );
if(!isset($_SESSION['counter']))
{
$_SESSION['counter']=1;
echo "歡迎光臨";
}
else
echo "已登錄過請勿重複登入";
?〉〈/body〉〈/html〉





七、 表單與Session:
1. 表單部分(1.php)

〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉表單登入〈/title〉〈/head〉〈body〉
〈form name="form1" method="post" action="2.php"〉請輸入姓名:
〈input type="text" name="username" maxlength="6" size="8"〉〈br〉
請輸入密碼:
〈input type="password" name="passwd" maxlength=”6” size="8"〉〈br〉
〈input type="submit"〉〈input type="reset"〉〈/form〉 〈/body〉〈/html〉




2. 接收表單資料

〈? session_start( ); ?〉〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉驗證表單資料〈/title〉〈/head〉〈body〉 〈?
if(!isset($_POST['username']))
{
?〉
〈script〉
window.alert('請輸入帳號');
//history.back( );
location.href="http://localhost/class3/session/1.php";
〈/script〉〈?
}
if(!isset($_POST['passwd']))
{
?〉
〈script〉
window.alert('請輸入密碼');
//history.back( );
location.href="http://localhost/class3/session/1.php";
〈/script〉
〈?
}
if($_POST['username']=="")
{ ?〉
〈script〉
window.alert('請輸入帳號');
history.back( );
//location.href="http://localhost/class3/session/1.php";
〈/script〉〈?
}
if($_POST['passwd']=="")
{
?〉
〈script〉
window.alert('請輸入密碼');
history.back( );
//location.href="http://localhost/class3/session/1.php";
〈/script〉
〈?
}
$_SESSION['username']=$_POST['username'];
$_SESSION['passwd']=$_POST['passwd'];
echo '〈br/〉〈a href="3.php"〉第三頁〈/a〉';
?〉〈/body〉〈/html〉




3. 第三頁的連結

〈? session_start( ); ?〉〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉查閱資料〈/title〉〈/head〉〈body〉 〈?
if(!isset($_SESSION['username']))
{
?〉
〈script〉
window.alert('請輸入帳號');
location.href='./1.php';
〈/script〉
〈?
}
if(!isset($_SESSION['passwd']))
{
?〉
〈script〉
window.alert('請輸入密碼');
location.href='./1.php';
〈/script〉
〈?
}
echo '歡迎光臨';
echo '〈br/〉〈a href="4.php"〉登出〈/a〉';
?〉〈/body〉〈/html〉




4. 第四頁登出




〈? session_start( ); ?〉〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉登出〈/title〉〈/head〉〈body〉 〈?
session_unset( );
session_destroy( );
?〉
〈script〉
//window.alert('請輸入帳號');
location.href='./1.php';
〈/script〉
〈/body〉〈/html〉




八、 Cookie基本練習
1. 儲存Cookie


〈? ob_start( ) ;?〉
〈html〉〈head〉〈meta http-equiv="content-type" content="text/html;charset=utf-8"〉
〈title〉儲存Cookie〈/title〉〈/head〉
〈body〉〈?
setcookie ("a", "php", time( )+1800);//1800代表1800秒
?〉〈/body〉〈/html〉



2. 顯示Cookie


〈html〉〈head〉〈meta http-equiv="content-type" content="text/html;charset=utf-8"〉
〈title〉顯示Cookie〈/title〉〈/head〉
〈body〉〈?
if (isset($_COOKIE["a"]))
echo "cookie內容為".$_COOKIE["a"];
else
echo "沒有資料";
?〉〈/body〉〈/html〉



3. 刪除Cookie(時間到期)

〈? ob_start( ) ;?〉
〈html〉〈head〉〈meta http-equiv="content-type" content="text/html;charset=utf-8"〉
〈title〉刪除Cookie〈/title〉〈/head〉
〈body〉〈?
setcookie ("a", "php", time( )-1800);
?〉〈/body〉〈/html〉




4. 刪除Cookie(變數沒有內容)

〈? ob_start( ) ;?〉
〈html〉〈head〉〈meta http-equiv="content-type" content="text/html;charset=utf-8"〉
〈title〉儲存Cookie〈/title〉〈/head〉
〈body〉〈?
setcookie ("a", "", time( )+1800);
?〉〈/body〉〈/html〉




九、 Cookie綜合練習
1. 設定Cookie,檔名為showcookie1.php

〈?ob_start( );?〉
〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉 cookies設定綜合練習〈/title〉〈/head〉〈body〉
〈?$tomorrow = mktime (0,0,0,date("m"),date("d")+1,date("Y")); //mktime
$nextmonth = mktime (0,0,0,date("m")+1,date("d"),date("Y"));
$nextyear = mktime (0,0,0,date("m"),date("d"),date("Y")+1);
$yourname="第6個cookie,Cookie變數的內容由變數取得資料";
$testtime=mktime(0,0,0,3,13,2009);
setcookie ("a[0]","設定保存1800秒", time( )+1800);
setcookie ("a[1]","設定保存至2009年3月13日",$testtime);
setcookie ("a[2]","設定保存至明天",$tomorrow);
setcookie ("a[3]","設定保存至下一個月",$nextmonth);
setcookie ("a[4]","設定保存至明年",$nextyear);
setcookie("a[5]","$yourname",time( )+1800);
echo '〈a href="showcookie2.php"〉查詢Cookies〈/a〉';
?〉〈/body〉〈/html〉





2. 查詢Cookie,檔名為showcookie2.php


〈?ob_start( );?〉
〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉 cookies設定綜合練習查詢〈/title〉〈/head〉〈body〉〈?
$value1=$_COOKIE["a"];
for ($for1=0;$for1〈5;$for1++)
{ $a=$for1+1;
echo "第".$a."的內容為".$value1[$for1]."〈br〉";
}
echo '〈a href="showcookie1php"〉重新建立Cookies〈/a〉〈br〉';
echo '〈a href="showcookie3.php"〉刪除幾個Cookies〈/a〉〈br〉';
?〉〈/body〉〈/html〉



3. 刪除Cookie:檔名為showcookie3.php


〈?ob_start( );?〉
〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉 cookies設定綜合練習刪除〈/title〉〈/head〉〈body〉〈?
echo "設定保存1800秒,現在減1800秒"."〈br〉";
echo "設定保存至2009年3月13日,現在內容沒了"."〈br〉";
setcookie ("a[0]","",time( )-1800);//內容沒了
setcookie ("a[1]","");//內容沒了
echo '〈a href="showcookie1php"〉重新建立Cookies〈/a〉〈br〉';
echo '〈a href="showcookie3.php"〉刪除幾個Cookies〈/a〉〈br〉';
?〉〈/body〉〈/html〉




十、 header運用—轉移網頁
〈? header("Location: http://www.google.com"); ?〉
Q1:如果此例的utf-8含有BOM,執行時會如何呢?
Q2:如果網頁上還有其他資訊顯示,網頁可以轉移嗎?


〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉轉換網址〈/title〉〈/head〉
〈body〉〈?
header("Location: http://www.google.com");

?〉
?〉〈/body〉〈/html〉



十一、 以下幾種函數都必須放在第一行,
且之前不能有任何輸出,包含空白:
header( )、setcookie( )、session_start( )、ob_start( )
十二、 header運用—驗證身份後做網頁轉換【提供表單網頁】



〈? ob_start( ) ;?〉
〈html〉〈head〉〈meta http-equiv="content-type" content="text/html;charset=utf-8"〉
〈title〉驗證帳號與密碼〈/title〉〈/head〉
〈body〉〈?
if (($_POST['username']=='php') and ($_POST['passwd']=='mysql'))
header("Location: success.php");
else header("Location: failed.php");
?〉〈/body〉〈/html〉




十三、 header運用—網頁每隔20秒向server讀取資料


〈? ob_start( ) ;?〉
〈html〉〈head〉〈meta http-equiv="content-type" content="text/html;charset=utf-8"〉
〈title〉網頁每隔20秒向server讀取資料〈/title〉〈/head〉
〈body〉〈?
header("refresh:20");
echo "現在時間:".date("h:i:s");
?〉〈/body〉〈/html〉



十四、 其他

星期一, 10月 18, 2010

PHP&MySQL--2 2010年10月課程講義預覽 修改

PHP&MySQL--2
一、 表單與資料接收的練習
1. text與password 表單【form1.html】:

〈html〉
〈head〉
〈title〉〈/title〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form1" method="post" action="1.php" 〉
username:〈input type="text" name="username" size="6"〉〈br〉
password:〈input type="password" name="passwd" maxlength="6" size="10"〉〈br〉
〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉
〈input type="button" value="what?"〉
〈/form〉
〈/body〉
〈/html〉




接收:


〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉〈/title〉〈/head〉〈body〉
〈?
echo "1:".$_POST['username']."〈br〉";
echo "2:".$_POST['passwd']."〈br〉";
echo "3:".$username."〈br〉";
echo "4:".$passwd."〈br〉";
echo "5:".$_GET['username']."〈br〉";
echo "6:".$_GET['passwd']."〈br〉";
?〉
〈/body〉〈/html〉



2. 選擇鈕
表單:


〈html〉
〈head〉
〈title〉〈/title〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form3" method="get" action="3.php" 〉
sex:
〈input type="radio" name="sex" value="boy"〉公的
〈input type="radio" name="sex" value="girl"〉母的
〈br〉
Blood:
〈input type="radio" name="blood" value="O"〉O
〈input type="radio" name="blood" value="A"〉A
〈input type="radio" name="blood" value="B"〉B
〈input type="radio" name="blood" value="AB" checked 〉AB
〈br〉
〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉 〈/form〉
〈/body〉
〈/html〉



接收:


〈html〉
〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉〈/title〉
〈/head〉
〈body〉
sex is 〈? echo $_GET['sex'];?〉〈br〉
blood is 〈? echo $_GET['blood'];?〉〈br〉
〈/body〉
〈/html〉




checked與disabled屬性的設定
3. 核選框
表單:


〈html〉
〈head〉
〈title〉〈/title〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form3" method="get" action="4.php" 〉
〈input type="checkbox" name="a" value="a"〉選項1
〈input type="checkbox" name="b" value="b"〉選項2
〈br〉
〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉 〈/form〉
〈/body〉
〈/html〉



接收:


〈html〉
〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉〈/title〉
〈/head〉
〈body〉
a is 〈? echo $_GET['a'];?〉〈br〉
b is 〈? echo $_GET['b'];?〉〈br〉
〈/body〉
〈/html〉



4. 下拉式選單
表單:


〈html〉
〈head〉
〈title〉〈/title〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form6" method="get" action="6.php" 〉
please select:
〈select name="travel" size="1"〉
〈option value="1"〉台北烏來〈/option〉
〈option〉台北101〈/option〉
〈option〉台北林家花園〈/option〉
〈option value="4" selected〉D〈/option〉
〈option value="5"〉E〈/option〉
〈option value="6"〉F〈/option〉
〈option value="7"〉G〈/option〉
〈option value="8"〉H〈/option〉
〈option value="9"〉I〈/option〉
〈/select〉〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉
〈/form〉
〈/body〉
〈/html〉



selected與disabled屬性的設定
接收:


〈html〉〈head〉〈meta http-equiv="content-type" content="text/html;charset=UTF-8"〉
〈title〉request select〈/title〉〈/head〉
〈body〉
〈? echo $_GET['travel'];?〉
〈/body〉〈/html〉



二、 表單傳遞的問題:表單資料必須透過網址列才可傳送到第三頁
1. 表單網頁【請將form1.html改存成form2.html】


〈html〉
〈head〉
〈title〉〈/title〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form2" method="post" action="form1.php" 〉
username:〈input type="text" name="username" size="6"〉〈br〉
password:〈input type="password" name="passwd" maxlength="6" size="10"〉〈br〉
〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉
〈input type="button" value="what?"〉
〈/form〉
〈/body〉
〈/html〉



2. 接收資料,並在下方加入連結【請將1.php改存成form1.php】


〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉〈/title〉〈/head〉
〈body〉〈?
echo "1:".$_POST['username']."〈br〉";
echo "2:".$_POST['passwd']."〈br〉";
$myname=$_POST['username'];
if($_POST['username']=="") die("沒有帳號");
?〉〈a href="form2.php"〉123〈/a〉
〈a href="form2.php?username=〈? echo $myname; ?〉"〉123〈/a〉
〈/body〉
〈/html〉



3. form2.php如果不經form1.php的情況下可以顯示資料嗎?

〈html〉
〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉〈/title〉
〈/head〉
〈body〉
是否有登入帳號的資訊?
〈?
echo "post方式傳送的帳號:".$_POST['username']."〈br〉"; ?〉
透過網址列傳送帳號,具有危險性:
〈?
echo "網址列傳送的帳號:".$_GET['username']."〈br〉"; ?〉
〈/body〉
〈/html〉




三、 表單傳遞的問題:使用者可在本機儲存表單html送至Server


〈html〉
〈head〉
〈title〉〈/title〉
〈meta http-equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form2" method="post" action="http://localhost/class1/form1.php" 〉
username:〈input type="text" name="username" value="haha" size="6"〉〈br〉
password:〈input type="password" name="passwd" maxlength="6" size="10" value="cc"〉〈br〉
〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉
〈input type="button" value="what?"〉
〈/form〉
〈/body〉
〈/html〉



四、 介紹checkbox分組之前,先介紹陣列
1. 陣列初始化

〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉第一個陣列〈/title〉〈/head〉
〈body〉〈?
$chinese[0] = 80;
$chinese[1] = 60;
$chinese[2] = 90;
$chinese[3] = 50;
$chinese[4] = 70;
for ($a=0; $a〈5; $a++)
echo "$chinese[$a] 〈br〉" ;
?〉〈/body〉〈/html〉




2. 請問以下陣列,網路硬碟上所提供的資料是否有缺?


〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉第一個陣列,不給予索引值編號〈/title〉〈/head〉
〈body〉〈?
$chinese[ ] = 80;
$chinese[ ] = 60;
$chinese[ ] = 90;
$chinese[ ] = 50;
$chinese[ ] = 70;
for ($a=0;$a〈5;$a++)
echo "座號".$a."同學的成績為:".$chinese[$a]."〈br〉" ;
?〉〈/body〉〈/html〉



3. 陣列可用array方式規劃,網路硬碟上所提供的資料是否有缺?


〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉以array方式建立陣列,索引值編號任意給〈/title〉〈/head〉
〈body〉〈?
$chinese=array(
1=〉80,
3=〉60,
6=〉90,
8=〉50,
9=〉70
);
for ($a=0;$a〈=10;$a++)
echo "座號".$a."同學的成績為:".$chinese[$a]."〈br〉" ;
?〉〈/body〉〈/html〉



4. 陣列可用文字做為索引,不過要如何看到全部資料?


〈html〉〈head〉
〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉以array方式建立文字型態索引值陣列〈/title〉〈/head〉
〈body〉〈?
$a=array(
"Jan" =〉 "一月",
"Feb" =〉 "二月",
"Mar" =〉 "三月"
);
echo $a["Mar"]."〈br〉";
?〉〈/body〉〈/html〉



五、 for與foreach差別
1. 由「陣列可用array方式規劃」練習修改後比較,有何差別?

for ($a=0;$a〈=10;$a++)
echo $chinese[$a]."〈br〉" ; foreach ($chinese as $value1)
echo $value1."〈br〉";




2. 由「陣列可用文字做為索引」練習修改,加入foreach讀取所有資料


foreach ($a as $value1)
echo $value1."〈br〉";



3. 由「陣列可用array方式規劃」練習修改,更快速顯示索引值與內容


foreach ($chinese as $key1 =〉$value1)
echo "座號".$key1."同學的成績為:".$value1."〈br〉" ;



六、 session start():檔名為session1.php

〈? session_start(); ?〉
〈html〉〈head〉〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉 session start()〈/title〉〈/head〉〈body〉 〈?
echo '〉〉第一頁〈〈';
$_SESSION['color'] = '漂亮';
$_SESSION['city'] = '台北';
$_SESSION['time'] = date("Y年m月d日 H時i分s秒");
echo '〈br /〉〈a href="session2.php"〉第二頁〈/a〉';
?〉〈/body〉〈/html〉




檔名為session2.php


〈? ob_start();//output buffering on
session_start(); //啟動 session
?〉
〈html〉〈head〉〈meta http-equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉 session start() page2〈/title〉〈/head〉〈body〉 〈?
echo '〉〉第二頁〈〈 〈br /〉';
echo $_SESSION['color']."〈br〉";
echo $_SESSION['city']."〈br〉";
echo date("Y年m月d日 H時i分s秒")." ==〉 ".$_SESSION['time'];
echo '〈br/〉〈a href="session1.php"〉第一頁〈/a〉';
?〉〈/body〉〈/html〉



七、 php5的時間調整:date.timezone -〉 Asia/Tokyo或Asia/Taipei
八、 session時間的初始化


〈? //ob_start();
session_start(); //啟動 session
ini_set('date.timezone','Asia/Tokyo');
?〉



備註:session暫存路徑修改 ini_set('session.save_path','../');
九、 其他

星期五, 10月 15, 2010

這幾個月我就不會將課表貼在部落格上

最近趕著寫第二本書,所以課表並未在部落格上公布,巨匠學員若對我的課程有興趣,
可與台北東區認證中心聯絡與詢問,這幾個月我就不會將課表貼在部落格上,謝謝!

PHP&MySQL--2 2010年10月課程講義預覽

PHP&MySQL--2
一、 表單與資料接收的練習
1. text與password 表單【form1.html】:
〈html〉
〈head〉
〈title〉〈/title〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form1" method="post" action="1.php"〉
username:〈input type="text" name="username" size="6"〉〈br /〉
password:〈input type="password" name="passwd" maxlength="6" size="10"〉〈br /〉
〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉
〈input type="button" value="what?"〉
〈/form〉
〈/body〉
〈/html〉
接收:
〈html〉〈head〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉〈/title〉〈/head〉〈body〉
〈?
echo "1:".$_POST['username']."〈br /〉";
echo "2:".$_POST['passwd']."〈br /〉";
echo "3:".$username."〈br /〉";
echo "4:".$passwd."〈br /〉";
echo "5:".$_GET['username']."〈br /〉";
echo "6:".$_GET['passwd']."〈br /〉";
?〉
〈/body〉〈/html〉
2. 選擇鈕
表單:
〈html〉
〈head〉
〈title〉〈/title〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form3" method="get" action="3.php"〉
sex:
〈input type="radio" name="sex" value="boy"〉公的
〈input type="radio" name="sex" value="girl"〉母的
〈br /〉
Blood:
〈input type="radio" name="blood" value="O"〉O
〈input type="radio" name="blood" value="A"〉A
〈input type="radio" name="blood" value="B"〉B
〈input type="radio" name="blood" value="AB"〉AB
〈br /〉
〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉 〈/form〉
〈/body〉
〈/html〉
接收:
〈html〉
〈head〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉〈/title〉
〈/head〉
〈body〉
sex is 〈? echo $_GET['sex'];?〉〈br /〉
blood is 〈? echo $_GET['blood'];?〉〈br /〉
〈/body〉
〈/html〉
checked與disabled屬性的設定
3. 核選框
表單:
〈html〉
〈head〉
〈title〉〈/title〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form3" method="get" action="4.php"〉
〈input type="checkbox" name="a" value="a"〉選項1
〈input type="checkbox" name="b" value="b"〉選項2
〈br /〉
〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉 〈/form〉
〈/body〉
〈/html〉
接收:
〈html〉
〈head〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉〈/title〉
〈/head〉
〈body〉
a is 〈? echo $_GET['a'];?〉〈br /〉
b is 〈? echo $_GET['b'];?〉〈br /〉
〈/body〉
〈/html〉
4. 下拉式選單
表單:
〈html〉
〈head〉
〈title〉〈/title〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form6" method="get" action="6.php"〉
please select:
〈select name="travel" size="1"〉
〈option value="1"〉台北烏來〈/option〉
〈option〉台北101〈/option〉
〈option〉台北林家花園〈/option〉
〈option value="4"〉D〈/option〉
〈option value="5"〉E〈/option〉
〈option value="6"〉F〈/option〉
〈option value="7"〉G〈/option〉
〈option value="8"〉H〈/option〉
〈option value="9"〉I〈/option〉
〈/select〉〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉
〈/form〉
〈/body〉
〈/html〉
selected與disabled屬性的設定
接收:
〈html〉〈head〉〈meta equiv="content-type" content="text/html;charset=UTF-8"〉
〈title〉request select〈/title〉〈/head〉
〈body〉
〈? echo $_GET['travel'];?〉
〈/body〉〈/html〉
二、 表單傳遞的問題:表單資料必須透過網址列才可傳送到第三頁
1. 表單網頁【請將form1.html改存成form2.html】
〈html〉
〈head〉
〈title〉〈/title〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form2" method="post" action="form1.php"〉
username:〈input type="text" name="username" size="6"〉〈br /〉
password:〈input type="password" name="passwd" maxlength="6" size="10"〉〈br /〉
〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉
〈input type="button" value="what?"〉
〈/form〉
〈/body〉
〈/html〉
2. 接收資料,並在下方加入連結【請將1.php改存成form1.php】
〈html〉
〈head〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉〈/title〉
〈/head〉
〈body〉
〈?
// put your code here
echo "1:".$_POST['username']."〈br /〉";
echo "2:".$_POST['passwd']."〈br /〉";
$myname=$_POST['username'];
if($_POST['username']=="") die("沒有帳號");
?〉
〈a href="form2.php"〉123〈/a〉
〈a href="" username="〈?"〉"〉123〈/a〉
〈/body〉
〈/html〉
3. form2.php如果不經form1.php的情況下可以顯示資料嗎?
〈html〉
〈head〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈title〉〈/title〉
〈/head〉
〈body〉
是否有登入帳號的資訊?
〈?
echo "post方式傳送的帳號:".$_POST['username']."〈br /〉"; ?〉
透過網址列傳送帳號,具有危險性:
〈?
echo "網址列傳送的帳號:".$_GET['username']."〈br /〉"; ?〉
〈/body〉
〈/html〉
三、 表單傳遞的問題:使用者可在本機儲存表單html送至Server
〈html〉
〈head〉
〈title〉〈/title〉
〈meta equiv="Content-Type" content="text/html; charset=UTF-8"〉
〈/head〉
〈body〉
〈form name="form2" method="post" action="http://localhost/class1/form1.php"〉
username:〈input type="text" name="username" value="haha" size="6"〉〈br /〉
password:〈input type="password" name="passwd" maxlength="6" size="10" value="cc"〉〈br /〉
〈input type="submit" value="ok"〉〈input type="reset" value="cancel"〉
〈input type="button" value="what?"〉
〈/form〉
〈/body〉
〈/html〉
四、 回顧與思考:
1. 如何做條件判斷:請參考網路硬碟上所提供的表單與接收資料檔案,並確認這樣的條件判斷是否正確?
2. 如何判斷是否有接收表單資料:請參考網路硬碟上所提供的表單與接收資料檔案,並確認若沒經過表單執行會如何?另請思考若經過表單但沒有輸入資料又會如何?
3. for迴圈會如何執行:請參考網路硬碟上所提供的PHP檔案,並確認若條件改為以下的條件,PHP會如何執行?
for ($i=1;$i〈=10;$i--) for ($i=1;$i!=10;$i+=2)
for ($i=1;$i〉=10;$i++)
4. 另外兩種迴圈的特色:請參考網路硬碟上所提供的PHP檔案
5. 迴圈如何中斷:請參考網路硬碟上所提供的PHP檔案分別進行修改,並請觀察執行結果。
〈html〉〈head〉〈meta equiv="Content-Type" content="text/html; charset=utf-8"〉〈title〉exit、break、continue...中斷指令〈/title〉〈/head〉〈body〉
〈?
for ($i=1; $i〈=10; $i++){
if($i==5){
echo "迴圈停止〈br /〉";
exit;
}
$a = $a+$i;
} 〈?
for ($i=1; $i〈=10; $i++){
if($i==5){
echo "迴圈停止〈br /〉";
break;
}
$a = $a+$i;
} 〈?
for ($i=1; $i〈=10; $i++){
if($i==5){
echo '$i=5迴圈停止〈br /〉';
continue;
}
$a = $a+$i;
}
echo "總和是:";
echo $a; ?〉〈/body〉〈/html〉
五、 介紹checkbox分組之前,先介紹陣列
1. 陣列初始化
〈html〉〈head〉
〈meta equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉第一個陣列〈/title〉〈/head〉
〈body〉〈?
$chinese[0] = 80;
$chinese[1] = 60;
$chinese[2] = 90;
$chinese[3] = 50;
$chinese[4] = 70;
for ($a=0; $a〈5; $a++)
echo "$chinese[$a] 〈br /〉" ;
?〉〈/body〉〈/html〉
2. 請問以下陣列,網路硬碟上所提供的資料是否有缺?
〈html〉〈head〉
〈meta equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉第一個陣列,不給予索引值編號〈/title〉〈/head〉
〈body〉〈?
$chinese[ ] = 80;
$chinese[ ] = 60;
$chinese[ ] = 90;
$chinese[ ] = 50;
$chinese[ ] = 70;
for ($a=0;$a〈5;$a++)
echo "座號".$a."同學的成績為:".$chinese[$a]."〈br /〉" ;
?〉〈/body〉〈/html〉
3. 陣列可用array方式規劃,網路硬碟上所提供的資料是否有缺?
〈html〉〈head〉
〈meta equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉以array方式建立陣列,索引值編號任意給〈/title〉〈/head〉
〈body〉〈?
$chinese=array(
1=〉80,
3=〉60,
6=〉90,
8=〉50,
9=〉70
);
for ($a=0;$a〈=10;$a++)
echo "座號".$a."同學的成績為:".$chinese[$a]."〈br /〉" ;
?〉〈/body〉〈/html〉
4. 陣列可用文字做為索引,不過要如何看到全部資料?
〈html〉〈head〉
〈meta equiv="Content-Type" content="text/html; charset=utf-8"〉
〈title〉以array方式建立文字型態索引值陣列〈/title〉〈/head〉
〈body〉〈?
$a=array(
"Jan" =〉 "一月",
"Feb" =〉 "二月",
"Mar" =〉 "三月"
);
echo $a["Mar"]."〈br /〉";
?〉〈/body〉〈/html〉
六、 for與foreach差別
1. 由「陣列可用array方式規劃」練習修改後比較,有何差別?
for ($a=0;$a〈=10;$a++)
echo $chinese[$a]."〈br /〉" ; foreach ($chinese as $value1)
echo $value1."〈br /〉";
2. 由「陣列可用文字做為索引」練習修改,加入foreach讀取所有資料
foreach ($a as $value1)
echo $value1."〈br /〉";
3. 由「陣列可用array方式規劃」練習修改,更快速顯示索引值與內容
foreach ($chinese as $key1 =〉$value1)
echo "座號".$key1."同學的成績為:".$value1."〈br /〉" ;
七、 其他