Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中将复选框值从一个页面传递到另一个页面_Php_Html_Sql - Fatal编程技术网

在php中将复选框值从一个页面传递到另一个页面

在php中将复选框值从一个页面传递到另一个页面,php,html,sql,Php,Html,Sql,如何在PHP中将复选框值从一个页面发送到另一个页面?复选框值是从数据库中提取的。我需要将选中的值从一个页面发送到另一个页面。我是php新手 page1.php <form method="post" action="setupstates.php"> <table border=".3px" id='acttable'> <tr> <td><b>Act Name</b></td>

如何在PHP中将复选框值从一个页面发送到另一个页面?复选框值是从数据库中提取的。我需要将选中的值从一个页面发送到另一个页面。我是php新手

page1.php

<form method="post" action="setupstates.php">
  <table border=".3px" id='acttable'>
    <tr>
      <td><b>Act Name</b></td>
      <td colspan="5"><input type='text' name="actname" size="130" required></td>
    </tr>
    <tr>
      <td><b>Industry Type</b></td>
      <td colspan="5"><input type="checkbox">
        Select All Industries</td>
      <?php
                $conn = get_dbconnect();
                $sql1 = "SELECT*FROM industry";
                $result = mysqli_query($conn, $sql1);
                $nrows = mysqli_num_rows($result);
                //echo $nrows;

                $sql = "SELECT name FROM industry"; //selection query
                $rs = mysqli_query($conn, $sql); //odbc_exec($conn,$sql);
                // if(mysqli_num_rows($rs)>0){
                while ($nrows > 0) {
                    echo "<tr>";
                    for ($i = 0; $i < 5; $i++) {
                        $row = mysqli_fetch_assoc($rs);
                        echo "<td><input type='checkbox' name='industrytype' value='" . $row['name'] . "'/>" . $row['name'];
                    }
                    $nrows = $nrows - 5;
                    echo '</tr>';
                }
                ?>
    </tr>
  </table>
  <input type="submit">
</form>

艺名
行业类型
选择所有行业
页面2.php(setupstates.php)


行业类型

您正在传递多个复选框值,而不是一个。这意味着您的setupdstates.php需要是一个循环来处理所有值

请注意,复选框很奇怪。如果不进行检查,则不会向PHP发送任何内容。因此,您将只获得已检查的

<?php //page1.php ?>
<form method="post" action="setupstates.php">
    <table border=".3px" id='acttable'>
    <tr>
        <td><b>Act Name</b></td>
        <td colspan="5"><input type='text' name="actname" size="130" required></td>

    </tr>
    <tr>
        <td><b>Industry Type</b></td>
        <td colspan="5"><input type="checkbox">Select All Industries</td>
        <?php 
            $conn = get_dbconnect();
            $sql1 = "SELECT * FROM industry";
            $result = mysqli_query($conn, $sql1);
            $nrows = mysqli_num_rows($result);
            //echo $nrows;

            $sql= "SELECT name FROM industry"; //selection query
            $rs = mysqli_query($conn, $sql);//odbc_exec($conn,$sql);
            // if(mysqli_num_rows($rs)>0){
            $n = 0;
            while( $nrows > 0 ) {
                echo "<tr>";
                for($i=0; $i < 5; $i++) {
                $row = mysqli_fetch_assoc($rs); 
                    // 
                    echo "<td><input type='checkbox' name='industrytype[]' value='".$row['name']."' onclick=checkall();/>".$row['name'] . "</td>";
                }
                $nrows = $nrows-5;
                echo '</tr>';
            }    
        ?>
    </tr>
    </table>

    <?php // setupstates.php ?>
    <table>
        <?php foreach ($_POST["industrytype"] as $value) : ?>
        <tr>
            <td><b>Industry Type</b></td>
            <td>
                <input type="checkbox" value="<?php print $value; ?>">
            </td>
        </tr>
        <?php endforeach; ?>
    </table>

艺名
行业类型
选择所有行业
行业类型

试试这个。它会对你有用的

 page1.php

    <form method="post" action="setupstates.php">
      <table border=".3px" id='acttable'>
        <tr>
          <td><b>Act Name</b></td>
          <td colspan="5"><input type='text' name="actname" size="130" required></td>
        </tr>
        <tr>
          <td><b>Industry Type</b></td>
          <td colspan="5"><input type="checkbox">
            Select All Industries</td>
          <?php
                    $conn = get_dbconnect();
                    $sql1 = "SELECT*FROM industry";
                    $result = mysqli_query($conn, $sql1);
                    $nrows = mysqli_num_rows($result);
                    //echo $nrows;

                    $sql = "SELECT name FROM industry"; //selection query
                    $rs = mysqli_query($conn, $sql); //odbc_exec($conn,$sql);
                    // if(mysqli_num_rows($rs)>0){
                    while ($nrows > 0) {
                        echo "<tr>";
                        for ($i = 0; $i < 5; $i++) {
                            $row = mysqli_fetch_assoc($rs);
                            echo "<td><input type='checkbox' name='industrytype[]' value='" . $row['name'] . "'/>" . $row['name'];
                        }
                        $nrows = $nrows - 5;
                        echo '</tr>';
                    }
                    ?>
        </tr>
    <tr><td colspan="5"><input type="submit" name="submit" value="submit"></td></tr>
      </table>
      <input type="submit">
    </form>


setupstates.php


<?php

if($_POST){
$chk = array();
$chk = $_POST['industrytype'];
$total = count($chk);
for($i=0; $i<$total; $i++){?>
<input type="checkbox" checked="checked" value="<?php echo $chk[$i] ?>"><?php echo $chk[$i]?>

<?php}}?>
page1.php
艺名
行业类型
选择所有行业
setupstates.php

此代码确实有效:-

创建第一页-index.php


form action=“process.php”method=“post”>
选择您的兴趣:
JAVA
PHP
python
JavaScript
提交
创建第二个页面-Process.php


课程:


输出:-课程:Java-PHP-Python-JavaScript

在setupstates中命名为数组industrytype[]使用$\u POST['industrytype']获取值page1中的submit按钮在哪里。phpafter标记am使用submit按钮。其内部格式仅打印($\u POST);在setupstates.php文件上,并在此处打印您得到了什么?为什么要使用$nrows=$nrows-5?$nrows=$nrows-5;有什么用?总计有18个复选框值,使用$nrow在每行am中显示5个复选框值$nrow仅用于对齐此答案是否有您不喜欢的地方?我只想将选中的值传递到另一页$\u POST[“行业类型”]包含上一页的所有选中值。
 page1.php

    <form method="post" action="setupstates.php">
      <table border=".3px" id='acttable'>
        <tr>
          <td><b>Act Name</b></td>
          <td colspan="5"><input type='text' name="actname" size="130" required></td>
        </tr>
        <tr>
          <td><b>Industry Type</b></td>
          <td colspan="5"><input type="checkbox">
            Select All Industries</td>
          <?php
                    $conn = get_dbconnect();
                    $sql1 = "SELECT*FROM industry";
                    $result = mysqli_query($conn, $sql1);
                    $nrows = mysqli_num_rows($result);
                    //echo $nrows;

                    $sql = "SELECT name FROM industry"; //selection query
                    $rs = mysqli_query($conn, $sql); //odbc_exec($conn,$sql);
                    // if(mysqli_num_rows($rs)>0){
                    while ($nrows > 0) {
                        echo "<tr>";
                        for ($i = 0; $i < 5; $i++) {
                            $row = mysqli_fetch_assoc($rs);
                            echo "<td><input type='checkbox' name='industrytype[]' value='" . $row['name'] . "'/>" . $row['name'];
                        }
                        $nrows = $nrows - 5;
                        echo '</tr>';
                    }
                    ?>
        </tr>
    <tr><td colspan="5"><input type="submit" name="submit" value="submit"></td></tr>
      </table>
      <input type="submit">
    </form>


setupstates.php


<?php

if($_POST){
$chk = array();
$chk = $_POST['industrytype'];
$total = count($chk);
for($i=0; $i<$total; $i++){?>
<input type="checkbox" checked="checked" value="<?php echo $chk[$i] ?>"><?php echo $chk[$i]?>

<?php}}?>