2016-10-01 41 views
0

我有這種形式如何提交表單到同一頁面,並得到結果顯示

<form action="" method="GET" id="formSearch"> 
      <div class="input-group"> 
       <input type="text" class="form-control" id="inputSearch" name="inputSearch"/> 
       <span id="spanBtnSearch" class="input-group-btn"> 
        <input type="submit" class="btn btn-primary" id="btnSearch" value="Search"/> 
       </span> 
      </div>   
     </form> 

我要發送這種形式在同一個頁面,我的連接和查詢上低於

<?php 
$conn = mysqli_connect("localhost:3311","root","root","compared"); 
$shingpoint = "SELECT * FROM products WHERE store LIKE 'shingpoint' AND title LIKE '%".$_POST['inputSearch']."%'"; 
$result = mysqli_query($conn,$shingpoint); 
?> 

而且應該顯示結果的結果是這樣的

<div class="row" id="divShingpoint"> 
     <h2 class="section-title style2 text-left">Shingpoint</h2> 
     <div id="divProductThumbnail" class="item col-lg-4 col-md-4 col-sm-4 col-xs-6 col-xxs-12 colums"> 
      <div class="container" id="divInnerContainer"> 
      <?php while ($shingpointrow = mysqli_fetch_assoc($result)) {?> 
       <div class="product"> 
        <div class="image"><img class="img-responsive" src="<?php echo $shingpointrow['img'] ?>" alt="<?php echo $shingpointrow['title']?>"/></div> 
        <div class="description"><h4 class="productname"><?php echo substr(trim($shingpointrow['title']),0,20) ?></h4></div> 
        <div class="price"> 
         <span><?php echo $shingpointrow['price'] ?></span> 
         <input type="button" class="btn btn-primary btn-sm" value="Details"/> 
        </div> 
       </div> 
      <?php }?> 
      </div> 
     </div> 
    </div>  

它確實發送數據,因爲頁面刷新並且url已啓動過期但結果不顯示在我想要搜索的標題div。用C inputSearch:

而且我收到此錯誤

注意:未定義指數\ wamp64 \第3行

什麼缺什麼我做錯了WWW \ compareit.php?或者有任何其他方法來完成任務?

回答

0

您將方法設置爲GET,但您嘗試從$ _POST讀取。

因此,要麼將<form method="POST">$_POST['inputSearch']更換爲$_GET['inputSearch']

除此之外,我想補充一些驗證,使用PDO和改變一些事情......

0

表單應具有方法而不是得到

相關問題