2012-07-20 272 views
0

嗨我試圖運行以下查詢,但似乎沒有返回 我想要的是我的作業表中選擇job_type返回job_discription。SQL查詢不返回任何東西

任何幫助都會很大,因爲我花了幾個小時試圖解決它。

謝謝

艾倫

<input type="hidden" name="JOB_TYPE" value="<?php print $_POST['JOB_TYPE'];?>"/> 

<?php 
$Query = " (SELECT JOB_TYPE, JOB_DISCRIPTION FROM jobs " . 
"WHERE jobs.JOB_TYPE ='$_POST[JOB_TYPE]' " . 
"AND jobs.JOB_DISCRIPTION = 'JOB_DISCRIPTION')"; 

$Result = mysqli_query($DB, $Query); 
?> 

<?php 
$Result = mysqli_query($DB,$Query)or die(mysqli_error($DB)); 

while ($Row = mysqli_fetch_assoc($Result)) // Now we go through the data displaying 
{ 

print $Row ['JOB_DISCRIPTION'] ; 

} 
?> 
+0

重複的問題。繼續[SQL查詢似乎不工作](http://stackoverflow.com/questions/11582594/sql-query-doesnt-seem-to-work) – codewaggle 2012-07-22 01:12:40

回答

1

從末尾刪除AND聲明:

AND jobs.JOB_DISCRIPTION = 'JOB_DISCRIPTION' 

而且來自各地的查詢語句刪除括號()

2

首先,代碼非常容易出現sql注入:您不應該直接使用$ _POST數據。如果您需要特定類型的描述,請刪除最後一個條件。

+1

+1關於清理'$ _POST'數據的好處。以下是關於如何處理任何感興趣的人的討論:[htmlentities vs htmlspecialchars](http://stackoverflow.com/questions/46483/htmlentities-vs-htmlspecialchars) – codewaggle 2012-07-21 00:09:32

0
" -- quotation marks are only required at the start and end 
SELECT JOB_TYPE 
    , JOB_DISCRIPTION -- some people spell description with an 'e' 
    FROM jobs 
WHERE jobs.JOB_TYPE =$_POST['JOB_TYPE'] -- escape data (using modern methods) to prevent injection and note 
    AND jobs.JOB_DISCRIPTION = 'JOB_DISCRIPTION'; -- This is really strange 
"