从动态生成的表单中获取值以放入php脚本的var

时间:2014-03-12 17:40:19

标签: php forms checkbox drop-down-menu

我有一个带有下拉列表和复选框列表的表单......它们都是从数据库中动态生成的。

如何从php脚本中将所选值(从下拉列表和复选框中获取)作为变量?

以下是表单的代码:

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

Title: <input type="text" name="title" size="80"><br><br>

Location: <input type="text" name="loco"><br><br>

Company: <select name="comp">

<option value="">Select Company</option>

<?php

 $con = mysql_connect('localhost','root','*******') or die (mysql_error());

   mysql_select_db('database' , $con );


 // dropdown list ------ (can be from 1 to  50 )

  $sql = "SELECT `company`.`comp_name` , `company`.`id_comp`

   FROM `company`

   ORDER BY `company`.`comp_name` ASC";

    $result = mysql_query ($sql  , $con);

    while($row = mysql_fetch_array ($result)){

    echo '<option value="'.$row['id_comp'].'" 

    name="'.$row['comp_name'].'">'.$row['comp_name'].'</option>';
   }
    ?>
     </select>

   <br><br>

  // check box list ----(can be from 1 to  50 boxes )

  <?php

  $con = mysql_connect('localhost','root','*******') or die (mysql_error());

  mysql_select_db('database' , $con );

   $sql = "SELECT `category`.`category`, `category`.`id_cat`
   FROM `category`
   ORDER BY `category`.`category` ASC";

   $result = mysql_query ($sql  , $con);

   while($row = mysql_fetch_array ($result)){

    echo '<input type="checkbox" name="'.$row['id_cat'].'">'.$row['category'].'<br>';

   }
   ?>
   <br><br>

    &nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" style="background-color: #FFD700;">

     </form>

我需要从下拉列表中使用:

   value="'.$row['id_comp'].'" 

AND

  name="'.$row['comp_name'].'"

并从复选框中选择

name="'.$row['id_cat'].'"  
检查

....(可以是1个选项或多个)

谢谢......我对此很陌生,所以请怜悯:))

0 个答案:

没有答案