2011-12-23 59 views
0

我有一個PHP文件做一個查詢PHP查詢+ IF ELSE

function getFiles() 
{ 
    $solnid = $_GET[id]; 
    $query = mysql_query("SELECT * FROM library WHERE libr_solutionId = '$solnid' AND libr_deleted IS NULL") or die(mysql_error()); 
    $result = mysql_query($query); 
    if (mysql_num_rows($result)==0) { 
     echo "<br>No Related Links"; 
    } else { 
     while($library = mysql_fetch_assoc($query)) { 
      echo "<span style=\"margin-bottom: 5px;\"><a href=\"Solutions/image/".$library[libr_solutionref]."/".$library[libr_filename]."\" target=\"_blank\"><img src=\"images/icon-download-02.png\" align=\"absmiddle\" style=\"margin-right: 5px;\"><span>".$library[libr_c_title]."</span></a></span><br>"; 
      echo "<br>"; 
     } 
    }  
} 

我已經測試在phpMyAdmin查詢,並運行在我的頁面中的功能時,只顯示「暫無相關我得到的結果卻鏈接'聲明任何想法的人?

+1

首先你的腳本中有大量的SQL注入。 – RageZ 2011-12-23 09:43:11

+0

我知道,但它是一個封閉的系統,所以這不是一個問題 – 2011-12-23 09:44:13

+0

數據庫是一樣的嗎? – macjohn 2011-12-23 09:45:58

回答

4

這裏是固定的代碼。 :)問題是,您使用的mysql_query上的資源(第一的mysql_query),這將給予0行,或異常..

function getFiles() 
{ 
    $solnid = $_GET['id']; 
    $result = mysql_query("SELECT * FROM library WHERE libr_solutionId = '$solnid' AND libr_deleted IS NULL") or die(mysql_error()); 
    if (mysql_num_rows($result)==0) { 
     echo "<br>No Related Links"; 
    } else { 
     while($library = mysql_fetch_assoc($result)) { 
      echo "<span style=\"margin-bottom: 5px;\"><a href=\"Solutions/image/".$library['libr_solutionref']."/".$library['libr_filename']."\" target=\"_blank\"><img src=\"images/icon-download-02.png\" align=\"absmiddle\" style=\"margin-right: 5px;\"><span>".$library['libr_c_title']."</span></a></span><br>"; 
      echo "<br>"; 
     } 
    }  
} 
+0

完美的感謝您的幫助和時間我真的很感激它! – 2011-12-23 09:47:33

+0

您還應該清理'$ solnid'的參數,可以像現在一樣利用SQL並進行一些注入。 :) – NoLifeKing 2011-12-23 09:49:58

+0

好聽!當我通讀它時,完全錯過了double mysql_query。 – Patches 2011-12-23 09:50:40

0

改變你的函數(變更線)

function getFiles() 
{ 
    $solnid = $_GET[id]; 
    $result = mysql_query("SELECT * FROM library WHERE libr_solutionId = '$solnid' AND libr_deleted IS NULL") or die(mysql_error()); 
    if (mysql_num_rows($result)==0) { 
     echo "<br>No Related Links"; 
    } else { 
     while($library = mysql_fetch_assoc($query)) { 
      echo "<span style=\"margin-bottom: 5px;\"><a href=\"Solutions/image/".$library[libr_solutionref]."/".$library[libr_filename]."\" target=\"_blank\"><img src=\"images/icon-download-02.png\" align=\"absmiddle\" style=\"margin-right: 5px;\"><span>".$library[libr_c_title]."</span></a></span><br>"; 
      echo "<br>"; 
     } 
    }  
}