dongxiangchan0743 2017-03-05 02:29
浏览 64

为什么我的$ _POST回来了一个空数组?

Good afternoon! So, I'm running into a few problems with my PHP code, here. I'm not exactly certain why, but upon pressing the submit button, no information is sent to $_POST. Any reasoning as to why this is?

The data sent into the html document is written into a php multidimensional associative array.

My code is posted below.

<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>
  • 写回答

2条回答 默认 最新

  • dsceme82487 2017-03-05 02:34
    关注

    Forms use the GET method by default. You must explicitly set method="post" on your <form> tag for browsers to submit the request as POST and populate the $_POST superglobal. The method attribute on <input> tags is meaningless, as details about sending data to the server are applied form-wide.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算