2017-03-05 3 views
0

おはよう!だから、ここで私のPHPコードにいくつかの問題があります。 理由はわかりませんが、送信ボタンを押すと$ _POSTに情報は送信されません。なぜこれが何であるかについてのいかなる推論?

htmlドキュメントに送信されるデータは、PHP多次元連想配列に書き込まれます。

マイコードは以下のとおりです。

<html> 
<?php 
$pageId = "Quiz"; 
$questions = array(
    array('question' => 'How do you install Apache2 on Debian?', 
     'answer' => 'sudo apt-get install apache2', 
     'choices' => array('1' => 'apt-get update', '2' => 'sudo apt-get install apache2', '3' => "sudo apt-get install apache", '4' => 'apt-get install apache2',), 
    ), 
    array('question' => 'What command enables ufw?', 
     'answer' => 'sudo ufw enable', 
     'choices' => array('1' => 'sudo ufw allow', '2' => 'sudo ufw enable 80', '3' => 'ufw allow', '4' => 'sudo ufw enable',), 
    ), 
    array('question' => 'What ports do you keep open to ensure your web content can be driven?', 
     'answer' => '80 and 443', 
     'choices' => array('1' => '80 and 443', '2' => '88 and 441','3' => "80 and 4443", '4' => '90 and 433',), 
    ), 
    array('question' => 'What OS was this tutorial tailored for?', 
     'answer' => 'Debian', 
     'choices' => array('1' => 'Debian', '2' => 'Ubuntu','3' => 'CentOS', '4' => 'FreeBSD',), 
    ), 
    array('question' => 'What are some of the benefits to setting up your own web server?', 
     'answer' => 'choice 1 data', 
     'choices' => array('1' => 'choice 1 data', '2' => 'choice 2 data',), 
    ), 
); 
include 'includes/header.html.php'; 
echo '<pre>'; 
print_r($_POST); 
echo '</pre>'; 
?> 

<div class="container" id="theBestStuff"> 
    <main> 
     <form> 
      <ol> 
<?php foreach ($questions as $q => $question) : ?> 
       <li><?= $question['question']?></li> 
<?php foreach ($question['choices'] as $c => $choice) : ?> 
       <label><input type="radio" name="question<?= $q ?>" value="<?= $choice ?>"><?= $choice ?></label> 
<?php endforeach; ?> 
<?php endforeach; ?> 
      </ol> 
      <input class="btn btn-info" action="" method="post" type="submit" value="submit"> 
     </form> 
    </main> 
</div> 

<?php 
include 'includes/footer.html.php'; 
?> 
</html> 

答えて

0

フォームuse the GET method by default<form>タグでmethod="post"を明示的に設定して、ブラウザが要求をPOSTとして送信し、$_POSTスーパーグローバルに入力する必要があります。 <input>タグのmethod属性は意味がありません。サーバーへのデータ送信の詳細がフォーム全体に適用されるためです。

+0

善良私のああ、あなたは正しいです!私はそれを知っていた。何かそんなにシンプルなもの... 数時間のトラブルシューティングの後でさえ、あなたはただ見落としていることの一つです。 –

1

あなたの<form>タグには属性が含まれていない可能性があります。

<form action="php_script_to_process_the_form.php" method="POST"> 

    ... Form elements ... 

    <input class="btn btn-info" type="submit" value="submit"> 

</form> 

は、それが取ることができる属性、利用可能なすべてのリストについては、W3Schoolsの上のタグを参照してください:それはしてきたはずですhttps://www.w3schools.com/tags/tag_form.asp

方法は=はmethod属性のデフォルト値である「GET」、およびそれは名前/値のペアでURLにフォームデータを追加:URL名前=値&名前=値

一方、

方法? =「POST」は、HTTPポストトランザクション

そして、フォームが送信されたときにフォームデータを送信するために=「URL」が指定

アクションとしてフォームのデータを送信します。 URLは絶対的なことがありますアクション= "http://www.example.com/example.php" をまたは相対:アクション= "example.php"

関連する問題