2017-09-09 28 views
1
<?php include 'db.php'; 

    $GLOBALS["conn"] = conncet(); 

    if (isset($_POST['submit'])) { 
     $ime = $_POST['ime']; 
     $rm = $_POST['rm']; 
     $minpl = $_POST['minpl']; 
     $maxpl = $_POST['maxpl']; 

     $query = "select * from zaposleni where ime = '{$ime}' and radno_mesto = '{$rm}' and plata between '{$minpl}' and '{$minpl}'"; 
     $result = mysqli_query($GLOBALS["conn"], $query); 

     if (!$result) { 
      echo "Query failed" . mysqli_error($GLOBALS["conn"]); 
     } 

     $count = mysqli_num_rows($result); 

      if ($count == 0) { 
       echo "NO RESULT"; 
      } else { 

     while($row = mysqli_fetch_assoc($result)) { 
      $i = $row['ime']; 
      $r = $row['radno_mesto']; 
      $p = $row['plata']; 

       ?> 

       <table> 
     <thead> 
      <tr> 
       <th>Ime:</th> 
       <th>Radno mesto:</th> 
       <th>Plata:</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
       <td><?php echo $i; ?></td> 
       <td><?php echo $r; ?></td> 
       <td><?php echo $p; ?></td> 
      </tr> 
     </tbody> 
    </table> 


       <?php 
      } } 
     if ($ime == "" || $rm = "" || $minpl = "" || $maxpl = "") { 
      echo "Morate uneti sva polja"; 
     } 

      } 


    ?> 


    <form action="" method="post"> 
     <div class="form-group"> 
      <label for="ime">Ime:</label> 
      <input type="text" class="form-control" name="ime"> 
     </div> 

     <div class="form-group"> 
      <label for="rm">Radno mesto:</label> 
      <input type="text" class="form-control" name="rm"> 
     </div> 

     <div class="form-group"> 
      <label for="minpl">MIN Plata:</label> 
      <input type="text" class="form-control" name="minpl"> 
     </div> 

     <div class="form-group"> 
      <label for="maxpl">MAX Plata:</label> 
      <input type="text" class="form-control" name="maxpl"> 
     </div> 

     <input type="submit" name="submit" value="Pretraga"> 
    </form> 

データベースが不足していても、結果は表示されません。それはなぜ機能しないのですか?この問題の提案はありますか?構文エラーはありません。たぶんクエリ?PHPクエリの結果がありません

https://files.fm/u/dgamw5uu#/view/Stack.PNGこれはデータベースのリンクです。

P.S.関数conncet()の名前はエラーではなく、関数名のスペルが間違っています。

IMEが名前を意味し、 radno_mestoは、作業場所を意味 分プラタは、最小限の給与を意味 最大プラタが最大の給与

+1

クエリを出力してDBで実行しますが、結果は表示されますか?あなたはSQLインジェクションにオープンしています。 '{$ minpl} 'と' {$ minpl} 'の間には誤植のように見えます。 '$ maxpl'にする必要がありますか? – chris85

+0

パラメトリッククエリについては – Strawberry

+0

をご覧ください。ありがとう、私は一日を "間違い"を探して過ごしたと信じることはできません。それはちょうど私のタイプミスです... –

答えて

0

を意味し、私はあなたのクエリの構文としてこれをしようとするだろう:(あなたが二回minplを使用)

$query = "select * from zaposleni where ime = '".$ime."' and radno_mesto = '".$rm."' and plata between ".$minpl." and ".$maxpl ; 

正しい値が$ ime、$ rm、$ minpl adn $ maxplに投稿されます

+0

ありがとう、それは動作します –

関連する問題