为了账号安全,请及时绑定邮箱和手机立即绑定

在不同页面上显示复选框输出

在不同页面上显示复选框输出

PHP
慕森王 2022-01-08 14:39:56
如何在不同的 php 页面上显示输出,非常感谢您的帮助,谢谢<?php$connect=mysqli_connect("localhost","root","","test"); $sql = "SELECT * FROM icheck "; $result = mysqli_query($connect, $sql); //$row = mysqli_fetch_array($result);?>//MY FIRST PAGE<form method="POST"><table>    <thead>        <tr>            <th>ID</th>            <th>Name</th>            <th>Price</th>            <th>Check</th>        </tr>    </thead>    <?php    if(mysqli_num_rows($result)>0){        $i=1;    while($row=mysqli_fetch_array($result))    {echo'<tr>    <td>'.$row['id'].'</td>    <td>'.$row['name'].'</td>    <td>'.$row['price'].'</td>    <td><input type="checkbox" name="check[]" value='.$row['id'].'></td>    ';    $i++;    }    }        ?></table><input type="submit" name="submit" Value="Submit"/></form>//OUTPUT TO BE DISPLAYED ON OTHER PAGE or 2nd PAGE<?php if(isset($_POST['submit'])){if(!empty($_POST['check'])) {// Counting number of checked checkboxes.$checked_count = count($_POST['check']);echo "You have selected following ".$checked_count." option(s): <br/>";if(isset($_POST['check'])){$sum=0;foreach($_POST['check'] as $selected) {    $ah="SELECT * FROM icheckWHERE id=".$selected;    $rowz = mysqli_query($connect, $ah);    $row=mysqli_fetch_array($rowz);    echo $row['name']."</br>";    $test=$row['price'];    $sum+=(int)$test;}echo "Jay Total na ket: ".$sum;}}else{echo "<b>Please Select Atleast One Option.</b>";}}?>
查看完整描述

2 回答

?
侃侃尔雅

TA贡献1801条经验 获得超16个赞

您在第一页中的表单不包含表单操作,因此您必须将表单操作放到第二页,然后可以从第二页捕获发布的数据。


//我的第一页


<form method="POST" action="mysecondpage.php">

<table>

    <thead>

        <tr>

            <th>ID</th>

            <th>Name</th>

            <th>Price</th>

            <th>Check</th>

        </tr>

    </thead>

    <?php

    if(mysqli_num_rows($result)>0){

        $i=1;


    while($row=mysqli_fetch_array($result))

    {

echo'<tr>

    <td>'.$row['id'].'</td>

    <td>'.$row['name'].'</td>

    <td>'.$row['price'].'</td>

    <td><input type="checkbox" name="check[]" value='.$row['id'].'></td>


    ';

    $i++;

    }

    }

        ?>


</table>

<input type="submit" name="submit" Value="Submit"/>

</form>


查看完整回答
反对 回复 2022-01-08
?
慕田峪4524236

TA贡献1875条经验 获得超5个赞

起初 vardump 这个$_POST['check']。它是数组吗,您的代码可以工作。通过 vardump 变量,您可以找到解决方案。

您可以与我分享您的 vardump 结果。


查看完整回答
反对 回复 2022-01-08
  • 2 回答
  • 0 关注
  • 123 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信