【问题标题】:From this php coding i want to get the values of checkboxes along with the regno. and inserted to database(mysql)从这个 php 编码中,我想获取复选框的值以及 regno。并插入数据库(mysql)
【发布时间】:2014-09-26 15:21:01
【问题描述】:

此表中的值是从数据库生成的,请参见附图。现在我需要从表中的复选框中获取值以及 regno(注册号)或名称。

 <form role="form" method="post">
          <label class="attendance"><strong>Date:</strong></label>
          <strong>
          <input  name="date" id="date" /></strong>
        </div>
        <table align="left" width="100%">
        <tr>
        <th>Rollno</th>
        <th>Regno</th>
        <th>Name</th>
        <th>Status</th>
        </tr>
<?php
 $query = "SELECT * FROM student where course='M.Sc.Software Systems' and year='4' ";
 $result=mysql_query($query) or die("Query Failed : ".mysql_error());
 while($rows=mysql_fetch_array($result))
 {                  
?>
    <tr>
    <td><?php echo $rows['rno'];?></td>   // values of rollno from database
    <td><?php echo $rows['regno']; ?></td>  // values of regno from database
    <td><?php echo $rows['name'];?></td>
    <td>
        <input type="checkbox" name="hour1" value="1"/>
        <input type="checkbox" name="hour2" value="1"/>
        <input type="checkbox" name="hour3" value="1"/>
        <input type="checkbox" name="hour4" value="1"/>
        <input type="checkbox" name="hour5" value="1" />   
    </td>
    </tr>
 <?php } ?>
</table>
  <button name='insert' type="submit" class="contact">Submit</button>
  </form>
 <?php
        if (isset($_POST['insert'])){
        $regno = $rows['regno1'];
        $hour1 = $_POST['hour1'];
        $hour2 = $_POST['hour2'];
        $hour3 = $_POST['hour3'];
        $hour4 = $_POST['hour4'];
        $hour5 = $_POST['hour5'];


        $query2 = "INSERT INTO attendance (regno,hour1,hour2,hour3,hour4,hour5) VALUES ('$regno','$hour1','$hour2','$hour3','$hour4','$hour5')";
        $result2=mysql_query($query2) or die("Query Failed : ".mysql_error());
        $message="Successfully Added";
        echo $message;
        mysql_close($connect_mysql);

        }   
        ?>

【问题讨论】:

  • 每一行都使用输入类型hidden
  • 你能发布更多的代码吗?这是一个不完整的片段(以'?>'开头)你可能想要做的是使用内联 if 语句添加“checked”关键字,如: > (未经测试的代码)
  • 为具有类似小时[]的数组的复选框赋予相同的名称
  • 我是初学者,对此我不太了解
  • 我尝试了 hour[] 但无法获得 regno 或 name

标签: php mysql checkbox


【解决方案1】:

试试下面:-

<td><?php echo $rows['rno'];?></td>   // values of rollno from database
        <td><?php echo $rows['regno']; ?></td>  // values of regno from database
        <td><?php echo $rows['name'];?></td>
        <td>
        <input type="hidden" name="regno" value="<?php echo $rows['regno']; ?>"/>
        <input type="checkbox" name="hour[]" value="1"/>
        <input type="checkbox" name="hour[]" value="1"/>
        <input type="checkbox" name="hour[]" value="1"/>
        <input type="checkbox" name="hour[]" value="1"/>
        <input type="checkbox" name="hour[]" value="1" />

您将在帖子中获得的价值(如果您使用过)

$_POST["regno"] for registeration number.

$_POST["hour"] 用于复选框值。

【讨论】:

  • 请告诉我如何从这个数组中获取值?
  • 但我有一个问题,它获取最后一个 regno 的输入。
  • 有什么问题?
  • regno 有很多。例如 11mss001 到 11mss008。值 11mss008 仅插入到数据库中
  • 你想存储所有的 regno 吗?
猜你喜欢
  • 1970-01-01
  • 2021-10-20
  • 2016-08-05
  • 1970-01-01
  • 1970-01-01
  • 2020-05-02
  • 2014-05-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多