• 締切済み

PHPがHTMLのformの値を受け取らない

状況: ファイルアップロードを作成しようとしたところPHPがHTMLのformのsubmitした物を受け取らない。 しかしHTML側にjavascriptを読み込ませ XMLHttpRequest によってsendすると受け取れる。 環境: apache 2.2.4 php 5.2.3 ------------HTML <html><body> <form action="test.php" enctype="multipart/form-data"> <input type="text" id="name"> <input type="file" id="file"> </form> </body></html> ------------PHP <?php header('Content-type: text/plain; charset=UTF-8'); print "\$_POST:";var_dump($_POST);print "\n"; print "\$_FILES:";var_dump($_FILES);print "\n"; ?> ------------結果 $_POST:array(0) { } $_FILES:array(0) { } ------------ 原因がphp.iniなのか、httpd.confなのか、はたまたそれ以外に原因があるのかがさっぱり判らず質問しました。 どうやったらHTMLのformの値をPHPで受け取れますか?

noname#39970
noname#39970

みんなの回答

  • kalze
  • ベストアンサー率47% (522/1092)
回答No.1

htmlのformにmethodが指定されていませんが、typoでしょうか? method="post"を指定していないとgetで送信されてしまうので、$_POSTの中身は空になります

noname#39970
質問者

補足

質問に書き写す時に失念しました。POSTの指定です。

関連するQ&A

  • FORMを教えてください

    全くの素人で、どなたか教えて下さい。 <HTML> <TITLE>TEST</TITLE> <BODY> <FORM ACTION="test.cgi" METHOD="POST"> 氏名<INPUT TYPE="TEXT" NAME="name"> 住所<INPUT TYPE="TEXT" NAME="tokoro"> <INPUT TYPE="Submit" value="データ送信"> <INPUT TYPE="Reset" value="リセット"> </FORM> </BODY> </HTML> 名前と住所を記入して送信ボタンを押したら記入した内容が表示されるCGIプログラムを教えて下さい。 #!/usr/local/bin/perl print "Content-Type: text/html"; print "<html>\n"; print "<head><title>TEST</title></head>\n"; print "<body>\n"; #受け取ったデータを表示する print "氏名=$in{'namae'}\n"; print "住所=$in{'tokoro'}\n"; print "</body>\n"; print "</html>\n"; exit; とした場合 氏名= 住所= しか表示されません。 何が足りないのでしょうか?

    • 締切済み
    • CGI
  • 配列を使って値を受け取る方法で困っています(PHP)

    こんにちは、よろしくお願い致します。 現在使用している環境が2つあります。 Win2000+Apache1.3+PHP4.2.3 RedHatLinux8.0+Apache1.3+PHP4.2.3 そのうちLinux環境の方では、配列がうまく使えません。 お手数ですが、具体的な結果は test.html、test.phpのソースと実行結果をご覧下さい。 両方の環境のApacheやPHPの設定ファイルをチェックしたのですが 特に怪しいところはなく、とても困ってます。 アドバイスお願い致します。 (test.html)-- <HTML><BODY> <form action=./test.php method=post> <input type=input name=a[0] value="1"> <input type=input name=b[0] value="12"> <input type=input name=c[0] value="123"> <input type=input name=d[0] value="1234"> <input type=input name=e[0] value="12345"> <input type=input name=f[0] value="123456"> <input type=submit name=submit value="OK"> </form> </BODY></HTML> ------------ (test.php)-- <?php print_r($HTTP_POST_VARS); ?> ------------ 【 Win環境の結果 】 Array ( [a] => Array ( [0] => 1 ) [b] => Array ( [0] => 12 ) [c] => Array ( [0] => 123 ) [d] => Array ( [0] => 1234 ) [e] => Array ( [0] => 12345 ) [f] => Array ( [0] => 123456 ) [submit] => OK ) 【 Linux環境の結果 】 Array ( [a] => Array ( [0] => 1 ) [b] => Array ( [0] => 12 ) [c] => Array ( [0] => 123 ) [d] => Array ( [0] => ) [e] => Array ( [0] => 5 ) [f] => Array ( [0] => 56 ) [submit] => OK )

    • ベストアンサー
    • PHP
  • $_FILES関数

    $_FILES関数が使えなくて困っています。 phpのバージョンは4.4です。 ソースは以下のようなものです。 ================================= <?php print_r($_FILES); ?> <html> <body> <form action="<?= $_SERVER['PHP_SELF']?>" method="POST" enctype="multipart/form-data"> <input type="file" name="upfile"/> <input type="submit" value="アップロード"/> </form> <body> <html> ================================= "アップロード"ボタンを押すと、Array()とだけ表示されます。 どうしたら、$_FILES情報が取れるのか分かる方、アドバイスお願いします。

    • 締切済み
    • PHP
  • PHPでの変数引渡しに関して

    "HTML -> PHP1 -> PHP2"という順序で変数の引渡しを行いたいと考えております。 "HTML -> PHP1"への変数引渡しは正常なのですが、"PHP1 -> PHP2"への変数引渡しがうまくいかない状態です。 1) "HTML -> PHP1" ・HTML <form name="toroku" method="POST" action="result.phtml">  <input type="text" name="word1" size="34"></td></tr>  <input type="text" name="word2" size="34"></td></tr>  ・・・・ </form> ・PHP1(result.phtml) <? require('../include/init.inc'); $word1 = $_POST{'word1'}; $word2 = $_POST{'word2'}; $word3 = $_POST{'word3'}; $email = $_POST{'word7'}; $word8 = $_POST{'word8'}; $seireki = $_POST{'seireki'}; $tuki = $_POST{'tuki'}; $nitiji = $_POST{'nitiji'}; $result = pg_query($con, "select .........."); $rows = pg_num_rows($result); var_dump($HTTP_POST_VARS); ?> <FORM action="./result2.phtml" method="post"></FORM> ・結果 array(8) { ["word1"]=> string(6) "テスト"       ["word2"]=> string(6) "テスト"       ["word3"]=> string(6) "テスト"       ["word7"]=> string(16) "test1@test.co.jp"       ["word8"]=> string(16) "test1@test.co.jp"       ["seireki"]=> string(4) "2008"       ["tuki"]=> string(2)"01"       ["nitiji"]=> string(2) "01" } 2) "PHP1 -> PHP2" ・PHP2 <? var_dump($HTTP_POST_VARS); ?> ・結果 array(0) { } 2)でHTMLの変数を継続して渡したいのです。 ご存知のかたがいたしたら、ご教示頂ければと思います。

    • ベストアンサー
    • PHP
  • PHPをはじめて1日目なので・・・

    参考書を見ながらPHPの勉強を始めていますが、本のサンプルと全く同様にコーディングしているはずなのに、良い結果が得られずバグとなります。 formとpostを使って内容を渡すという項目なのですが。 form.htmlの内容。 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <form method="post" action="form1.php"> 好きな食べ物は?<input type="text" name="food1"><br> 好きな飲み物は?<input type="text" name="food2"> <input type="submit" value="送信"> </form> </body> </html> form1.phpの内容 <?php header('Content-type: text/html; charset=UTF-8'); ?> <html> <body> <?php $f1 = $_POST['food1']; $f2 = $_POST['food2']; $f1 = htmlentities( $f1, ENT_QUOTES, 'UTF-8' ); $f2 = htmlentities( $f2, ENT_QUOTES, 'UTF-8' ); echo 'あなたは「', $f1, "」が好きなんですね。<br>\n"; echo '「', $f2, "」も好きなんですね。<br>\n"; ?> </body> </html> おそらくちょっとしたことが原因でエラーが出ているのだと思いますが、まだ始めて1日目なので、どこがいけないのかさっぱりわかりません。 一体どこがおかしいのか、教えていただけますか?

    • ベストアンサー
    • PHP
  • javascript php フォームについて

    javascriptで作ったフォームをphpに送信したいのですが、上手く送信できません。 どのようにすれば上手く送信することができるでしょうか? 回答お願いします。 javascript側のソース <body> <form name="nform1" method="POST" action="./kaitou1.php" enctype="text/plain"> <p>問1</p> <p> (1)<input type="text" name="kaitouran11" size="20"> (2)<input type="text" name="kaitouran12" size="20"> (3)<input type="text" name="kaitouran13" size="20"> (4)<input type="text" name="kaitouran14" size="20"> </p> </form> <form name="nform2" method="POST" action="./kaitou1.php" enctype="text/plain"> <p>問2</p> <p> (1)<input type="text" name="kaitouran21" size="20"> (2)<input type="text" name="kaitouran22" size="20"> (3)<input type="text" name="kaitouran23" size="20"> (4)<input type="text" name="kaitouran24" size="20"> </p> </form> <form name="nform3" method="POST" action="./kaitou1.php" enctype="text/plain"> <p>問3</p> <p> (1)<input type="text" name="kaitouran31" size="20"> (2)<input type="text" name="kaitouran32" size="20"> (3)<input type="text" name="kaitouran33" size="20"> (4)<input type="text" name="kaitouran34" size="20"> </p> </form> <input type="button" value="送信" onClick="send()"> </body> php側のソース <body> <p>問1</p> <p>(1)<?php print(htmlspecialchars($_POST['kaitouran11'], ENT_QUOTES, 'UTF-8')); ?> (2)<?php print(htmlspecialchars($_POST['kaitouran12'], ENT_QUOTES, 'UTF-8')); ?> (3)<?php print(htmlspecialchars($_POST['kaitouran13'], ENT_QUOTES, 'UTF-8')); ?> (4)<?php print(htmlspecialchars($_POST['kaitouran14'], ENT_QUOTES, 'UTF-8')); ?> </p> <p>問2</p> <p>(1)<?php print(htmlspecialchars($_POST['kaitouran21'], ENT_QUOTES, 'UTF-8')); ?> (2)<?php print(htmlspecialchars($_POST['kaitouran22'], ENT_QUOTES, 'UTF-8')); ?> (3)<?php print(htmlspecialchars($_POST['kaitouran23'], ENT_QUOTES, 'UTF-8')); ?> (4)<?php print(htmlspecialchars($_POST['kaitouran24'], ENT_QUOTES, 'UTF-8')); ?> </p> <p>問3</p> <p>(1)<?php print(htmlspecialchars($_POST['kaitouran31'], ENT_QUOTES, 'UTF-8')); ?> (2)<?php print(htmlspecialchars($_POST['kaitouran32'], ENT_QUOTES, 'UTF-8')); ?> (3)<?php print(htmlspecialchars($_POST['kaitouran33'], ENT_QUOTES, 'UTF-8')); ?> (4)<?php print(htmlspecialchars($_POST['kaitouran34'], ENT_QUOTES, 'UTF-8')); ?> </p> </body>

    • 締切済み
    • PHP
  • phpエラー

    現在phpの練習をしてるんですが教科書通りにプログラミングをしてもうまく動きません。 次のコードでおかしな部分があるのでしょうか? よろしくお願いします。 <html> <head> <title>アップロード</title> </head> <body> <form enctype="multipart/for-data" action="http://192.168.11.8/upload.php" method="post"> ファイル:<input type="file" name="myfile"/><br/> <input type="submit" value="送信"/> </form> <?php if(isset($_FILES["myfile"]["tmp_name"])){ // myfileがスーパグローバルに一時ファイルとして保存されたら $filename = "./" . $_FILES["myfile"]["name"]; // その相対パスを格納 if(move_uploaded_file($_FILES["myfile"]["tmp_name"], $filename)){ // 第一引数の一時ファイルを第二引数の場所からアップロード print "送信しました。\n"; } else{ print "送信に失敗しました.\n"; } } ?> </body> </html>

    • ベストアンサー
    • PHP
  • forで作成したフォームの値を更にPHPへ渡して表示する方法

    初心者です。 現在、PHPでforを利用し、繰り返しフォームを表示 させた後、その表示されたフォームへ入力をし、更に 違うPHPで入力された値を出力させようとしているのですが、 最終の出力が出来ずに悩んでおります。 繰り返しでフォームを作成するまでは出来たのですが、 どなたか御助力頂けたら助かります。 ---------------------------------------------------- <form.html> <html> <head> <title>it1</title> </head> <body> <form name="form" action="./it.php" method="POST"> <b>ラジオ選択<br> <input name="machine" type="radio" value="24">24<br> <input name="machine" type="radio" value="48">48<br> <input name="machine" type="radio" value="24">50</b><br><br> </body> <input type="submit" name="Submit" value="設定"> </form> </html> ------------------------------------------------------ <it.php> <?php $a = $_REQUEST["machine"]; ?> <html> <body> <p>入力テキストボックス表示</p> <?php for ($c=0; $c<$a; $c++){ $var[$c] += $var[$c]; $dest[$c] += $dest[$c]; $no[$c] += $c+1; } ?> <table> <tr> <td><center> <form name="form" action="./it2.php" method="POST"> <td> <center> <b>vlan</b><br> <?php for ($i=0; $i<count($var); $i++) { "<form name="form" action="./it2.php" method="POST">" print("fa0/${no[$i]}<input type=\"text\" name=\"${var[$i]}\" size=\"3\" maxlength=\"3\"><br>\n"); } ?> </td> <td> <b>description</b><br> <?php for ($i=0; $i<count($dest); $i++) { print("<input type=\"text\" name=\"${dest[$i]}\" size=\"15\" maxlength=\"15\"><br>\n"); } ?> </td> </tr> </table> <input type="submit" name="Submit" value="設定"> </form> </body> </html> -------------------------------------------------------- 以降の出力ソースに関して、難儀中。

    • ベストアンサー
    • PHP
  • PHPについて教えてください

    以下のコードでthanks.phpにemailとgoikenが表示されません なぜでしょうか? おそらくthanks.phpが間違えてると思いますが見直してもわかりません index.html <DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>PHP基礎</title> </head> <body> <form method="POST" action="check.php"> ニックネームを入力してください<br> <input name="nickname" type="text" style="width:100px"><br> メールアドレスを入力してください<br> <input name="email" type="text" style="width:200px"><br> ご意見を一言でお聞かせください<br> <input name="goiken" type="text" style="width:300px"><br> <input type="submit" value="送信"> </form> </body> </html> check.php <DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>PHP基礎</title> </head> <body> <?php $nickname=$_POST['nickname']; $email=$_POST['email']; $goiken=$_POST['goiken']; if ($nickname==''){ print'ニックネームが入力されていません<br>'; } else { print'ようこそ'; print $nickname; print' 様'; print'<br>'; } if ($email==''){ print'メールアドレスが入力されていません<br>'; } else { print'メールアドレス:'; print $email; print'<br>'; } if ($goiken==''){ print'ご意見が入力されていません<br>'; } else { print'ご意見『'; print $goiken; print'』<br>'; } if($nickname=='' || $email='' || $goiken=''){ print'<form>'; print'<input type="button" onclick="history.back()" value="戻る">'; print'</form>'; } else { print'<form method="post" action="thanks.php">'; print'<input name="nickname" type="hidden" value="'.$nickname.'">'; print'<input name="email" type="hidden" value="'.$email.'">'; print'<input name="goiken" type="hidden" value="'.$goiken.'">'; print'<input type="button" onclick="history.back()" value="戻る">'; print'<input type="submit" value="OK">'; print'</form>'; } ?> </body> </html> thanks.php <DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>PHP基礎</title> </head> <body> <?php $nickname=$_POST['nickname']; $email=$_POST['email']; $goiken=$_POST['goiken']; print $nickname; print'様<br>'; print'ご意見ありがとうございました<br>'; print'頂いたご意見『'; print $goiken; print '』<br>'; print $email; print'宛にメールを送信しました'; ?> </body> </html>

    • ベストアンサー
    • PHP
  • PHPで求めた変数をHTMLで使う方法

    HTMLのformタグで与えた引数を元に、ある値をPHPで求めた後、その求めた変数をHTMLに戻って使う方法をご教授下さい。 例えば、 index.html ↓↓↓ <form action="submit.php" method="post"> <input type="text" name="xxxxx"> <input type="text" name="yyyyy"> <input tyoe="submit" value="実行"> </form> <textarea name="answer"> 実行後ここに、下のPHPで求めた$zzzzzを表示したい。 </textarea> 上のHTMLでxxxxxとyyyyyを入力して実行ボタンを押します。 そしてPHP側は、 submit.php  ↓↓↓ $zzzzz = $_POST["xxxxx"] . "は、" . $_POST["yyyyy"] . "です。"; このように求めた$zzzzzを上のHTMLに戻って表示したいのですが、しばらく調べてみても見つかりませんでした。 どなたかご教授下さい、お願いします。