组合多个POST并将其添加到表中


Combine multiple POSTs and adding it to table

下面是我为表添加多个类型的代码。我想将区域、位置和类型组合起来,并将它们一次添加到表中。我觉得这不管用if(!empty($_POST['types'] && $_POST[''] && $_POST[''] )谢谢!

if(!empty($_POST['types'])) {   
    $values = array();
    foreach($_POST['types'] as $typ_id) {
        $values[] = sprintf('(%d, %d)', $station_id, $typ_id);
    }
    $query = 'INSERT IGNORE INTO station_typ_tab
          (station_id, typ_id, area_id, location_id)
          VALUES ' .
          implode(',', $values);
          mysql_query($query, $db) or die(mysql_error($db));
   }

编辑:这是类型[]的部分代码,区域和位置也是如此

<td>Types:<br/> <small>CTRL + click to set multiple pollutants</em></small>
   </td>
   <td>
   <?php
    $query = 'SELECT typ_id, typ FROM typ_tab ORDER BY typ ASC';
    $result = mysql_query($query, $db) or die(mysql_error($db));
    if (mysql_num_rows($result) > 0) {
        echo '<select multiple name="types[]">';
        while ($row = mysql_fetch_array($result)) {
           if (isset($station_typ[$row['typ_id']])) {
              echo '<option value="' . $row['typ_id'] . '"
              selected="selected">';
              } else {
                  echo '<option value="' . $row['typ_id'] .'">'; 
              }
              echo $row['typ'] . '</option>';
           }
           echo '</selected>';
        } else {
          echo '<p><strong>Databaza je prazdna... <a href="edit_pollutant.php">Enter database</a></strong></p>';
        }
        mysql_free_result($result);

如果类型、位置和区域来自不同的选择输入,如何组合$_POST。类似if(!empty($_POST['types'] && $_POST['areas'] && $_POST['location']) ){ $values = array(); foreach( NEW VARIABLE as $typ_id && area_id &&location_id) { $values[] = sprintf('(%d, %d, %d, %d)', $station_id, $typ_id, area_id, location_id);的东西,如果可以这样做的话

要在IF中组合,请尝试使用

if((!empty($_POST['types'])) && (!empty($_POST['area'])) && (!$_POST['location'])));