2010-03-03 4 views
0

I 형태, 그것은 다음과 같은 값 전달이 :PHP : 일부 POST 변수를받지 못하고 있습니까?

image_title, 
image_description, 
image_file 

나는이 양식을 여러 번 제시하고 싶었을, 그래서 나는 다음 않았다

image_title_1, 
image_description_1, 
image_file_1 

image_title_2, 
image_description_2, 
image_file_2 

여러 번, 그래서 필드가 1 - 10. 폼을 제출하고 POST 배열의 내용을 출력합니다. 문제는 "image_title_1"이 배열에 없으면 "image_title_ #"입니다. 그러나 그 외 모든 것은 않습니다. 그래서 내가 1 이후 아니에요 여전히 표시되지 않습니다 서로 그러나 제목과 설명과 제목을 바꾼 무엇인지 작업

image_title_1 -> "title!" 
image_description_1 -> "description!" 
image_file_1 -> file 

image_description_2 -> "description!" 
image_file_2 -> file 

image_description_3 -> "description!" 
image_file_3 -> file 

:

그래서 배열과 같을 것 어떤 처리를하고 있어도 말 그대로 $ _POST 배열을 인쇄하고 있습니다. 이것은 의미가 없으며 무엇이 그것을 일으킬 수 있습니까?

명확히하기 : 문제는 image_title_1을 제외하고는 "image_title_ #"(예 : image_title_3)이 전달되지 않습니다. 주문을 재 배열해도 문제가되지 않습니다. 나는 출력하기 전에 아무런 처리도하지 않는다.

편집, HTML 소스는 다음과 같습니다

은 더 나은 솔루션을 배열로 변환 될 수
<form method="post" action=""> 
    <input type="text" name="image_title_1"></input> 
    <input type="text" name="image_description_1"></input> 
    <input type="text" name="image_file_1"></input> 

    <input type="text" name="image_title_2"></input> 
    <input type="text" name="image_description_2"></input> 
    <input type="text" name="image_file_2"></input> 

    <input type="text" name="image_title_3"></input> 
    <input type="text" name="image_description_3"></input> 
    <input type="text" name="image_file_3"></input> 

    <input type="submit" name="submit" value="submit"></input> 
</form> 
+0

양식의 HTML 소스를 표시 할 수 있습니까? –

+0

양식에 대해 * 생성 된 * HTML을 표시하십시오. –

+0

가능한 경우 코드를 표시해야합니다. – Sarfraz

답변

2

, 대신이 시도 :

<form method="post" action=""> 
    <input type="text" name="image_title[]"></input> 
    <input type="text" name="image_description[]"></input> 
    <input type="text" name="image_file[]"></input> 

    <input type="submit" name="submit" value="submit"></input> 
</form> 

지금, 당신의 PHP 스크립트에서, 당신이 얻을 수있는 그들의 배열은 다음과 같습니다 :

print_r($_POST['image_title']); 
print_r($_POST['image_description']); 
print_r($_POST['image_file']); 

.

필드 이름 뒤에 []을 붙이면 배열로 변환됩니다. 다른 좋은 점은 코드가 너무 짧다는 것입니다. 당신은 배열을 일단

, 당신이 foreach을 그들을 통해 루프를 사용 할 수 있습니다

foreach($_POST['image_title'] as $key => $value) 
{ 
    // process them any way you want 
} 
0

코드는 작동합니다. 난 그냥 잘라내어 양식을 붙여 시험을 제출해주세요.

Array 
(
[image_title_1] => 1 
[image_description_1] => 2 
[image_file_1] => 3 
[image_title_2] => 4 
[image_description_2] => 5 
[image_file_2] => 6 
[image_title_3] => 7 
[image_description_3] => 8 
[image_file_3] => 9 
[submit] => submit 
)