如何在多个搜索选项中发送数据

时间:2014-10-11 16:57:24

标签: php

大家好我在我的网站的自定义页面编码搜索php,并希望在同一页面中搜索工作(我不想将数据发送到操作页面)。 但我有问题我不知道为什么这不是工作请求可以有人告诉我什么是问题,什么是现在的?! 谢谢。

<div class="row-fluid">
        <div class="page-header">
            <h1>Search Users: </h1>
        </div>
        <center>
             <h2>Find user(s)</h2> 
        <form name="search" method="post" action="">
             Seach for: <input type="text" name="find" /> with 
             <Select NAME="field">
             <Option VALUE="user_id">User ID</option>
             <Option VALUE="username">Username</option>
             <Option VALUE="serialnumber">SerialNumber</option>
             <Option VALUE="ip_address">IP Address</option>
             </Select>
             <input type="hidden" name="searching" value="yes" />
             <input type="submit" name="search" value="Search" class="btn btn-success" style="vertical-align: super;" />
        </form>
        <span><?php echo $error; ?></span>
        </center>               
        <table class="table table-striped table-bordered table-condensed">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>E-mail</th>
                    <th>IP</th>
                    <th>serialnumber</th>
                    <th>Actions</th>
                </tr>
            </thead>
<?php
if (isset($_POST['submit'])) {

        if (empty($_POST['find']) || empty($_POST['field'])) {
            $error = "Pleas choice options"; 
            } 
        else 
        {

    $find=$_POST['find']; 
    $value=$_POST['field']; 

        $sql = "SELECT * FROM login_log WHERE '$value' = '$find'";
        $result = $db->sql_query($sql);

        while($row = $db->sql_fetchrow($result)) {
?>
            <tbody>
            <tr class="pending-user">
                <td><?php echo $row['user_id']; ?></td>
                <td><?php echo $row['username']; ?></td>
                <td><?php echo $row['email']; ?></td>
                <td><?php echo $row['ip_address']; ?></td>
                <td><?php echo $row['serialnumber']; ?></td>
                <td><a href="ban.php?id=<?php echo $row['user_id']; ?>&ip=<?php echo $row['ip_address']; ?>&sn=<?php echo $row['serialnumber']; ?>" class="btn btn-primary">Ban User</a></td>
            </tr>
            </tbody>
<?php 
        }
    }
 }
?>
        </table>
      </div>

1 个答案:

答案 0 :(得分:0)

$_POST将包含表单中使用表单字段的name=属性的元素。 $ _POST [&#39;提交&#39;]除非您有一个字段或按钮name="submit",否则不会存在。执行var_dump($ _ POST)以查看将哪些值发送回表单。

isset($_POST['submit'])更改为isset($_POST['search']

请参阅tutorial了解如何使用表单。