post방식으로 배열값 넘기기 질문입니다.
초보질문입니다
A.php 에서
폼값을
<form name="myform" method="post" action="result.php" role="form">
<fieldset>
<legend>취미를 선택해 주세요.</legend>
<!-- 설문항목 -->
<div class="checkbox">
<label>
<input type="checkbox" name="hobby[]" value="음악감상">
음악감상</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="hobby[]" value="영화감상">
영화감상</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="hobby[]" value="게임">
게임</label>
</div>
<button type="submit" class="btn btn-primary">결과보기</button>
</fieldset>
</form>
이런식으로 해서 result.php 로 배열로 넘겼는데요
result.php -------------내용입니다
$hobby = $_POST('hobby');
// 배열 데이터이기 떄문에 문자열로 합쳐야 출력 가능함.
$hobby_str = implode(", ", $hobby);
<?php echo $hobby_str;?>
이렇게 출력했는데도 값이 없습니다. ㅜㅜ
뭐가 잘못됐는지요?
A.php 에서
폼값을
<form name="myform" method="post" action="result.php" role="form">
<fieldset>
<legend>취미를 선택해 주세요.</legend>
<!-- 설문항목 -->
<div class="checkbox">
<label>
<input type="checkbox" name="hobby[]" value="음악감상">
음악감상</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="hobby[]" value="영화감상">
영화감상</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="hobby[]" value="게임">
게임</label>
</div>
<button type="submit" class="btn btn-primary">결과보기</button>
</fieldset>
</form>
이런식으로 해서 result.php 로 배열로 넘겼는데요
result.php -------------내용입니다
$hobby = $_POST('hobby');
// 배열 데이터이기 떄문에 문자열로 합쳐야 출력 가능함.
$hobby_str = implode(", ", $hobby);
<?php echo $hobby_str;?>
이렇게 출력했는데도 값이 없습니다. ㅜㅜ
뭐가 잘못됐는지요?
댓글 2개
골목대장1004
7년 전
$hobby = $_POST['hobby'];
for ($i=0; $i<count($hobby); $i++) {
echo $hobby[$i];
}
이렇게 해서 값체크 한번 해보시구요.
$hobby = $_POST('hobby'); -> $hobby = $_POST['hobby'];
으로 변경하세요.
for ($i=0; $i<count($hobby); $i++) {
echo $hobby[$i];
}
이렇게 해서 값체크 한번 해보시구요.
$hobby = $_POST('hobby'); -> $hobby = $_POST['hobby'];
으로 변경하세요.
5년 전
감사합니다
게시글 목록
| 번호 | 제목 |
|---|---|
| 32970 | |
| 32959 | |
| 32937 | |
| 32917 | |
| 32909 | |
| 32899 | |
| 32885 | |
| 32884 | |
| 32862 | |
| 32861 | |
| 32860 | |
| 32840 | |
| 32814 | |
| 32804 | |
| 32795 | |
| 32784 | |
| 32783 | |
| 32750 | |
| 32740 | |
| 32732 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기