同时从2个文件向php文件提交变量

时间:2017-04-02 09:46:18

标签: php html sql

我目前无法尝试进一步改进我的项目搜索机制。我认为自己是PHP的新手。下面的代码来自我的filter.php文件

<html>
        <link rel="stylesheet" href="../site/assets/css/reset.css" type="text/css">
        <link rel="stylesheet" href="../site/assets/css/main.css" type="text/css">
        <form action="search.php" method="GET">
           <div action="search.php" class="filt" >
              <ul >
                  <li onclick="myFunction()" >Offer type</li>
                  <li id="myDIV">
                       <ul>
                          <li><input type="radio" value="all"checked="checked"  name="offertype">all</input></li>
                          <li><input type="radio" value="free" name="offertype">free</input></li>
                          <li><input type="radio" value="trade"name="offertype">trade</input></li>
                          <li><input type="radio" value="sell" name="offertype">sell</input></li>
                        </ul>
                  </li>

                  <li onclick="myFunction2()">Publisher
                   <li id="myDIV2">
                     <input type="search" name="publisher" placeholder="enter publisher name">  
                  </li>
                  </li>

                  <li  onclick="myFunction3()">pricing</li>
                  <li id="myDIV3">

                          <ul>
                          <li><input type="radio" checked="checked" name="price order" value="low">Lowest to Highest</input></li>
                          <li><input type="radio" name="price order" value="high">Highest to Lowest </input></li>

                        </ul>   
                  </li>
                  </li >


              </ul> 

             </div>


         </form>

以下内容来自我的Header.PHP文件

<body>
    <header id="page_header">
        <nav>
            <ul>
                <a href="register.php"><li>Signup </li></a>
                <a href="login.php"><li>Login    </li></a>

            </ul>
        </nav>

        <!--Logo-->
        <div id="logo">
            <img src="assets/images/logo.png">
        </div> <!-- End of logo div -->

        <!--search box-->
    <div id="browse">
        <form action="search.php?" method="get">
            <fieldset>
                <select name="genre">
                    <option value="" selected>Genre</option>
                    <option value="Programming">Programming</option>
                    <option value="Non-fiction">Non-fiction</option>
                    <option value="Science fiction">Science fiction</option>
                    <option value="Satire">Satire</option>
                    <option value="drama">Drama</option>
                    <option value="Action &#38;"> Action and Adventure</option>


                </select>
                <input type="search" name="bookname" placeholder="Browse Books">
                <input type="submit"  value="Search">
            </fieldset>
        </form><!-- End of search form -->
    </div> <!-- End of seacrch form div -->



    </header> 

我正在尝试从标头和过滤器文件中同时从两个文件中进行变换。我该怎么做呢?

    <?php
include ( "../includes/db_connection.php" );
include ( "../includes/layouts/header.php" );
include( "../includes/layouts/filter.php" );
?>

    <?php

$BOOKNAME =  $_GET['bookname'];
$GENRE    =  $_GET['genre'];
$OFFER    =  $_GET['offertype'];
$PUB      =  $_GET['publisher'];

if(strlen($GENRE )=='0' ) {
    $sql="SELECT * FROM book WHERE  
    BOOKNAME LIKE '$BOOKNAME%' ";
}
else{
    $sql="SELECT * FROM book WHERE  
    BOOKNAME LIKE '$BOOKNAME%' AND GENRE LIKE '$GENRE'
    AND PUBLISHER LIKE '$PUB' ";    
}
$result = $connection->query($sql);

?>

0 个答案:

没有答案