form 태그를 이용한 값전달


index.php

1
2
3
4
5
6
<form method=post action="lecture10_form1.php">
    <input type="text" name="val01" size=5>
    <input type="text" name="operator" size=1>
    <input type="text" name="val02" size=5>    
    <input type="submit" value="계산하기">
</form>
cs


lecture10_form1.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?
    extract(array_merge($HTTP_GET_VARS,$HTTP_POST_VARS));
 
    switch($operator)
    {
        case("+"):
            $result=$val01+$val02;
            print $val01."+".$val02." = ".$result;
            break;
        case("-"):
            $result=$val01-$val02;
            print $val01."-".$val02." = ".$result;
            break;
        case("*"):
            $result=$val01*$val02;
            print $val01."*".$val02." = ".$result;
            break;
        case("/"):
            $result=$val01/$val02;
            print $val01."/".$val02." = ".$result;
            break;
    }
?>
cs

extract(array_merge($HTTP_GET_VARS,$HTTP_POST_VARS));

위 함수를 이용하여 GET, POST 방식을 이용할 수 있음


select 태그를 이용한 값 전달


index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
<form method=post action="lecture10_form1.php">
    <select name="val01" size="1">
        <option value="2">2단</option>
        <option value="3">3단</option>
        <option value="4">4단</option>
        <option value="5">5단</option>
        <option value="6">6단</option>
        <option value="7">7단</option>
        <option value="8">8단</option>
        <option value="9">9단</option>
    </select>
    <input type="submit" value="결과 보기">
</form>
cs

lecture10_form1.php

1
2
3
4
5
6
7
<?
    extract(array_merge($HTTP_GET_VARS,$HTTP_POST_VARS));
 
    print $val01."단 <p>";
    for($i=1;$i<10;$i++)
        print $val01." * "$i." = "$val01*$i."<br>";
?>
cs


라디오 박스, 체크박스 를 이용한 값전달


index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<form method=post action="phpnform3.php">
    이름 <input type="text" name="u_name" size=10>
    <br>
    성별 <input type="radio" name="sexual_type" value="남자">남  
         <input type="radio" name="sexual_type" value="여자" checked>여
    <br>
    관심사항 <input type="checkbox" name="interesting[]" value="Web Programming"> Web Programming  
    <input type="checkbox" name="interesting[]" value="Graphics"> Graphics  
    <input type="checkbox" name="interesting[]" value="Mathematics"> Mathematics  
    <input type="checkbox" name="interesting[]" value="Databases"> Databases
    <p>
    <input type="submit" value="전송"
    <input type="reset" value="다시쓰기">
</form>
cs


phpnform3.php

1
2
3
4
5
6
7
8
<?
    extract(array_merge($HTTP_GET_VARS,$HTTP_POST_VARS));
    print "이름: ".$u_name."<br>";
    print "성별: ".$sexual_type."<br>";
    print "관심사항: ";
    for($i=0;$i<count($interesting);$i++)
        print "[".$interesting[$i]."]";
?>
cs


​ 

'프로그래밍 > PHP' 카테고리의 다른 글

(PHP) Sort 함수를 이용하여 내림차순 정렬 만들기  (0) 2016.07.10
(PHP) for문과 배열  (0) 2016.07.10
(PHP) 배열과 정렬  (0) 2016.07.10
(PHP) 파일 사용하기  (0) 2016.07.10
(PHP) 클래스  (0) 2016.07.10

+ Recent posts