【问题标题】:How do I make sure my form comes in an array in PHP如何确保我的表单出现在 PHP 中的数组中
【发布时间】:2023-04-02 09:00:01
【问题描述】:

这个想法是,当您单击 Volgende 时,将 $getal1、$getal1、$soort 和 $antwoord 放入一个数组中。如果这是第 2 次,那就是第 1 次和第 2 次。

这是我的英文 PHP 代码

<?php   
$kind = $_SESSION['kind'];//get the kind of  task choose from +-/*
$class = $_SESSION['class'];//get the number of class
$answers = $_SESSION['answers'];//get the previous answers
if($class == "klas4"){
    $max = 10;
}
if($class == "klas5"){
    $max = 20;
}
if($class == "klas6"){
    $max = 100;
}
$number1 = mt_rand(0,  $max);
$number2 = mt_rand(0,  $max);
?>
<div class="som">
    <form action="" method="post">
        <?php echo $number1 . $kind . $number2 ?>
        <input name="answer" type="number">
        <input type="submit" name="next" value="next"> 
    </form>
</div>
<?php    
    if(isset($_POST['next']))
    {   
    $answer = $_POST['next'];
    $answers=array($answers);
    array_push($answers,$number1,$kind, $number2,$answer);

    var_dump($answers);
    $_SESSION['answers']=$answers;
    }
?>

如果这段代码被执行,所有的东西都会结合在一起。

希望有人能帮忙

【问题讨论】:

  • 使用 name=data[antwood]
  • 不管怎样都行不通,但你只是给他们发了$antwood,还是我错过了

标签: php multidimensional-array array-push


【解决方案1】:

顺便说一句,试着用英语编写你的代码,我是荷兰人,所以我可以阅读它,但用你自己的语言编写代码是不好的做法。

它不起作用的原因还在于 $antwooden 没有定义。 你不做任何计算。 您保存了 $antwooden,但再也不会从会话中取出它。

你能把整个脚本贴出来吗? 我认为你使用 1 个 php 文件。

我也认为你应该更清楚脚本应该做什么。

【讨论】:

  • 我把我的整个代码都改成了英文,但不明白你的意思。你能解释清楚吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多