将输入类型文本放入数组中 [英] put input type text in an array

查看:110
本文介绍了将输入类型文本放入数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文字输入输入产生,而循环产生。现在我想将放入一个数组中。像这样:

I have some text inputs. The inputs are produced from a while loop. Now I want put the values in an array. Like this:

array       values
mark['0']   input1
mark['1']   input2
mark['2']   input3

我试过这个但不工作。 <$ p
$ b

I tried this but not working.

while($row=mysql_fetch_array($result)){
  <form class="form1" name="form1" method="post">
    <input type="text" name="mark[]"/>
  </form>
}
<form class="form1" name="form1" method="post">
    <button type="submit" name="correction"></submit>
</form>

然后

And then

if(isset($_POST['correction'])){
$grade=0;   
    $mark=$_POST['mark'];
    foreach($mark as $key =>$value ){
        $grade+=$value;
    }   
print $grade;
}

我收到这些错误:

I get these errors:

Notice: Undefined index: mark in C:\xampp\htdocs\virtual_exam\handy_correction.php on line 37

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\virtual_exam\handy_correction.php on line 38

问题可能是由两种不相互连接的表单造成的,如果是,如何加入?
如果没有,如何做我想要的?

The problem may be caused by two forms which arent connected to each other and if YES, how to joined them? If NO, how to do what i want?

推荐答案

将您的表单更改为:

<form class="form1" name="form1" method="post">

  <?php
    while ($row = mysql_fetch_array($result)) {
      echo '<input type="text" name="mark[]" />';
    }
  ?>

  <input type="submit" name="correction" value="Submit" />
</form>

然后:

And then:

if (isset($_POST['correction'])) {
  $grade = 0;   
  $mark  = $_POST['mark'];

  foreach ($mark as $key => $value) {
    $grade += $value;
  }

  echo $grade;
}

这篇关于将输入类型文本放入数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆