<?php
$month=array(1,2,3,4,5,6,7,8,9,10);
foreach($month as $value)
$totle=$totle+$value;
echo "$totle<BR>";
foreach($_SERVER as $key=> $value) //檢視SERVER的INDEX與內容
echo "\$_SERVER [$key] : <B>$value</B><BR>"; //\為跳脫字元
?>
SELECT (GET)頁面內容
<BODY>
<BR><BR>
<FORM action="test.php" method="GET">
<select name=select1>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select><BR>
<select multiple name=select2[] size3>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
</select><BR>
<input type=submit name="submit">
</FORM>
</BODY>
TEST (GET)頁面內容
<?php
echo $_GET['select1']."<BR>";
if ($_GET['select2'])
foreach($_GET['select2'] as $value)
echo $value."<BR>";
else
echo "NO SELECT2";
?>
SELECT (POST)頁面內容
<BODY>
<BR><BR>
<FORM action="test.php" method="POST">
<select name=select1>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select><BR>
<select multiple name=select2[] size3>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
</select><BR>
<input type=submit name="submit">
</FORM>
</BODY>
TEST (POST)頁面內容
<?php
echo $_POST'select1']."<BR>";
if ($_POST['select2'])
foreach($_GET['select2'] as $value)
echo $value."<BR>";
else
echo "NO SELECT2";
?>
TEST (GET與POST皆可以處理的頁面)
<?php
if ($_GET['select1']){
$select1=$_GET['select1'];
if ($_GET['select2'])
$select2=$_GET['select2'];
}
if ($_POST['select1']){
$select1=$_POST['select1'];
if ($_POST['select2'])
$select2=$_POST['select2'];
}
echo $select1."<BR>";
if ($select2)
foreach($select2 as $value)
echo $value."<BR>";
else
echo "NO SELECT2";
?>
TEST (GET與POST皆可處理並完整檢查參數是否傳入)
<?php
if ($_SERVER[REQUEST_METHOD]==GET){
if ($_GET['select1']) $select1=$_GET['select1'];
if ($_GET['select2']) $select2=$_GET['select2'];
}
if ($_SERVER[REQUEST_METHOD]==POST){
if ($_POST['select1']) $select1=$_POST['select1'];
if ($_POST['select2']) $select2=$_POST['select2'];
}
if ($select1) echo $select1."<BR>";
else echo "NO SELECT1<BR>";
if ($select2)
foreach($select2 as $value)
echo $value."<BR>";
else
echo "NO SELECT2";
?>
留言列表