我从mysql填充表格。代码是。 。

task.php

<div data-role="content">
               <h2> Please select cars </h2>
<form method="post" action="cars.php">
            <?php
            $carq = "select * from cars";
            $executecars = mysql_query($carq);
            while($row=mysql_fetch_assoc($executecars)){
                $cname = $row['name'];
                ?>

               <label for="<?php echo $cname; ?>"><?php echo $cname; ?></label>
               <input type="checkbox" name="car" id="<?php echo $cname; ?>" value="<?php echo $cname; ?>"/>

            <?php }

            ?>
           <input type="submit" name="submitcars" id="submitcars" value="View Details"/>
           </form>
         </div>


现在在cars.php中,我想查询以显示所选汽车的详细信息,

<div data-role="content">
        <?php
            if(isset($_POST['submitcars'])){

                echo $_POST[$cname];?????????????


                }
        ?>

        </div>


现在如何在cars.php中处理表格?

谢谢

最佳答案

制作汽车属性数组:

<input type="checkbox" name="car[]" id="<?php echo $cname; ?>" value="<?php echo $cname; ?>"/>


并将它们放在下一页上

if(isset($_POST['submitcars'])){
   foreach($_POST['car'] as $car){
       // do something with $car
   }
}

10-05 17:56