猿问

为什么 post 方法检测不到提交的名称?

我有一个 9x9 字段。当我按下任何按钮时,我希望它显示坐标,但由于某种原因它没有。


有人知道哪里出错了吗?我在做一些不可能的事情吗?


当前代码:


<?php

echo "<iframe name='frame'></iframe>";

$aww_ar = array();

// SELECT PLAYING FIELD ValLUES

$th = 10;

$tw = 10;

// Amount of numbers

$amount = 5;

// Create 2d array

for ($y = 0;$y < $th;$y++) {

    for ($x = 0;$x < $tw;$x++) {

        $randomise = rand(1, $amount);

        $aww_ar[$x][$y] = $randomise;

    }

}


// create 2d table array

?>        

    <form method="post" target="frame" action="">

        <table>

        <?php

foreach ($aww_ar as $x => & $value) {

    echo "<tr>";

    foreach ($aww_ar[0] as $y => $v) {

        echo "<td><input type='submit' name='" . $x . ',' . $y . "' value='" . $aww_ar[$x][$y] . "'></td>";

    }

    echo "</tr>";

}

?>

        </table>

    </form>

    <?php

if (isset($_POST[$x . ',' . $y])) {

    echo $x . ',' . $y;

}


慕哥6287543
浏览 104回答 1
1回答

长风秋雁

我不确定 iframe 的目的是什么。如果您将字段重命名为使用下划线而不是逗号,则以下代码应打印单击按钮的值。<?phpif($_SERVER['REQUEST_METHOD'] == 'POST'){&nbsp; &nbsp; $value = $_POST['field'];&nbsp; &nbsp; echo $value;}&nbsp; &nbsp; $aww_ar = array();&nbsp; &nbsp; // SELECT PLAYING FIELD ValLUES&nbsp; &nbsp; $th = 10;&nbsp; &nbsp; $tw = 10;&nbsp; &nbsp; // Amount of numbers&nbsp; &nbsp; $amount = 5;&nbsp; &nbsp; // Create 2d array&nbsp; &nbsp; for($y = 0; $y < $th; $y++){&nbsp; &nbsp; &nbsp; &nbsp; for($x = 0; $x < $tw; $x++){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $randomise = rand(1,$amount);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $aww_ar[$x][$y] = $randomise ;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; // create 2d table array?>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <form method="post">&nbsp; &nbsp; &nbsp; &nbsp; <table>&nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; foreach ($aww_ar as $x=>&$value) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo"<tr>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach ($aww_ar[0] as $y=>$v) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<td><input type='submit' name='field' value='".$aww_ar[$x][$y]."'></td>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo"</tr>";&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; &nbsp; </table>&nbsp; &nbsp; </form>请注意,代码假定您的 post 数组中只有一个变量。
随时随地看视频慕课网APP
我要回答