0

我创建了一个包含多个复选框和一个包含所有 50 个状态的多个下拉列表的表单。我想从下拉表单中选择多个复选框和多个状态。我的问题当然是我......
所以当我查询我需要的信息时,它会出现空白。我可能会以错误的方式处理这一切。

<form name="search_form" method="post" action="event_list">
  <table>
    <tr>
      <td>Venue</td>
      <td><input type="checkbox" name="AAC" action="" value="AAC"/>
        <label >AAC</label>
        <br />
        <input type="checkbox" name="AKC" action="" value="AKC"/>
        <label >AKC</label>
        <br />
        <input type="checkbox" name="ASCA" action="" value="ASCA"/>
        <label >ASCA</label>
        <br />
        <input type="checkbox" name="CKE" action="" value="CKE"/>
        <label >CKE</label>
        <br />
        <input type="checkbox" name="CPE" action="" value="CPE"/>
        <label >CPE</label>
        <br />
        <input type="checkbox" name="DOCNA" action="" value="DOCNA"/>
        <label >DOCNA</label>
        <br />
        <input type="checkbox" name="NADAC" action="" value="NADAC"/>
        <label >NADAC</label>
        <br />
        <input type="checkbox" name="TDAA" action="" value="TDAA"/>
        <label >TDAA</label>
        <br />
        <input type="checkbox" name="UKC" action="" value="UKC"/>
        <label >UKC</label>
        <br />
        <input type="checkbox" name="UKI" action="" value="UKI"/>
        <label >UKI</label>
        <br />
        <input type="checkbox" name="USDAA" action="" value="USDAA"/>
        <label >USDAA</label>
        <br /></td>
    </tr>
    <tr>
      <td style="text-align: left;">State:</td>
      <td style="text-align: left;"><select name="state" id="state"  multiple="multiple" size="3" onchange="setCities();">
          <option value="Alabama">Alabama</option>
          <option value="Texas">Texas</option>
        </select></td>
    </tr>

      <td align="right"><input type="submit" name="search" value="Submit"></td>
    </tr>
  </table>
</form>

 <?php
  $sql=" SELECT * FROM venue_event ";

  if (isset($_POST['search']) && !empty($_POST['search'])){
 $search_term = mysql_real_escape_string($_POST['AAC']);
 $search_term2 = mysql_real_escape_string($_POST['state']);
 $search_term3 = mysql_real_escape_string($_POST['NADAC']);
 $search_term4 = mysql_real_escape_string($_POST['AKC']);
 $search_term5 = mysql_real_escape_string($_POST['ASCA']);
 $search_term6 = mysql_real_escape_string($_POST['CKE']);
 $search_term7 = mysql_real_escape_string($_POST['CPE']);
 $search_term8 = mysql_real_escape_string($_POST['TDAA']);
 $search_term9 = mysql_real_escape_string($_POST['UKC']);
 $search_term10 = mysql_real_escape_string($_POST['UKI']);
 $search_term11 = mysql_real_escape_string($_POST['USDAA']);

 $sql .= "WHERE venue = '{$search_term}' ";
 $sql .= "OR venue = '{$search_term3}' ";
 $sql .= "OR venue = '{$search_term4}' ";
 $sql .= "OR venue = '{$search_term5}' ";
 $sql .= "OR venue = '{$search_term6}' ";
 $sql .= "OR venue = '{$search_term7}' ";
 $sql .= "OR venue = '{$search_term8}' ";
 $sql .= "OR venue = '{$search_term9}' ";
 $sql .= "OR venue = '{$search_term10}' ";
 $sql .= "OR venue = '{$search_term11}' ";
 $sql .= "AND state = '{$search_term2}'"; //if I leave this out it 
     works with checkbox
 $sql .= "ORDER BY startdate ASC";


$result=mysql_query($sql) or die(mysql_error());
    }else{
    header('Location: /wordpress/venue_events'); exit();
    }
    ?>

    <?php

    echo "<table>
    <tr>
    <th>Club Host</th>
    <th>Venue</th>
    <th>Event Location</th>
    <th>Event Start date</th>
    <th>Event End Date</th>
    <th>Event Premium</th>
    </tr>";

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo '<td><a href="'.$row['user_url'].'" target="new" >'.$row['clubhost'].'
    </a> </td>';
    echo "<td>" . $row['venue'] . "</td>";
    echo "<td>" . $row['city'] ." ". $row['state'] ."</td>";
    echo "<td>" . $row['startdate'] . "</td>";
    echo "<td>" . $row['enddate'] . "</td>";
    echo  '<td><a href="../download.php?f='.$row['file_name'].'" >Download  Premium</a></td>';
    echo "</tr>";
    }
    echo "</table>";
    ?>
4

1 回答 1

1

您应该尝试用“info[]”替换每个名称,但保留您拥有的值。这是一个示例代码:

<form action="test.php" method="post">
<input type="checkbox" name="check_list[]" value="value 1">
<input type="submit" />
</form>
<?php
if(!empty($_POST['check_list'])) {
    foreach($_POST['check_list'] as $check) {
            echo $check; //echoes the value set in the HTML form for each checked checkbox.
                         //so, if I were to check 1, 3, and 5 it would echo value 1, value 3, value 5.
                         //in your case, it would echo whatever $row['Report ID'] is equivalent to.
    }
}
?>
于 2013-02-14T19:59:34.763 回答