index.php输出的Php-SQL不正确

时间:2016-01-27 19:56:55

标签: php html mysql sql search

我有一个带有简单表单的index.php文件,它将这些表中的值提交给searchAction.php文件。但是,从索引页面按下搜索后的输出与searchAction.php上按下的搜索按钮不同且不正确,即使两者都为searchAction执行相同的php。

    <?php
        //Start session
        session_start();    
        //Unset the variables stored in session
        unset($_SESSION['search']);
    ?>
 <html lang="en">

  <body>  

    <form id="searchbox" method="POST" action="searchAction.php">
        <select id= "selectType" name="combo">
            <option class="defualt-text">--Select Search Type--</option>
            <option value="0">ALL</option>
            <option value="1">Shopname</option>
            <option value="2">Shop Category</option>
            <option value="3">Product Name</option>
            <option value="4">Product Category</option>
        </select>
        <input id="search" type="text" placeholder="Search..." name="search">
        <input id="submit" type="submit" value="Search" name="submit">
    </form>
                <?php
                    if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
                        echo '$_SESSION["ERRMSG_ARR"]';
                        unset($_SESSION['ERRMSG_ARR']);
                    }
                ?>
    </body>

</html>

对于SearchAction.php

    <?php 
        $button = $_POST ['submit'];
        $search = $_POST ['search'];
        $option = $_POST ['combo'];
    ?>
<div id="top">

    <div id="topsbar">
        <form method="POST" action="searchAction.php">

            <input id="topsearch" type="text" name="search">
            <input id="topsubmit" type="submit" name="submit">
        </form>
    </div>
</div>

<hr size='1'>
<?php
    mysql_connect("localhost","root","root");
    mysql_select_db("db_tech");

    switch($option){

        case 0: $sql = "SELECT S.SHOPNAME, P.PRODUCTNAME,S.SHOPURL FROM sNameSearch S JOIN pNameSearch P ON S.SHOPID = P.SHOPID WHERE S.SHOPNAME LIKE '%".$search."%' ORDER BY S.SHOPNAME";
                break;
        case 1: $sql = "SELECT SHOPNAME,SHOPCAT,SHOPURL FROM sNameSearch WHERE SHOPNAME LIKE '%".$search."%' ORDER BY SHOPNAME";
                break;
        case 2: $sql = "SELECT SHOPNAME,SHOPCAT,SHOPURL FROM sNameSearch WHERE SHOPCAT LIKE '%".$search."%' ORDER BY SHOPCAT";
                break;

}

$run = mysql_query($sql);
$foundnum = mysql_num_rows($run);
echo $foundnum;
?>

0 个答案:

没有答案