2013-08-22 79 views
-6
$uid = $_GET['id']; 
echo $sql = "select * from notice where id=$uid"; 
echo $result = mysql_query($sql); 
$row = mysql_fetch_array($result); 
    echo $row['headline']; 
    echo $row['description']; 
    echo $row['image']; 

是生產mysql_fetch_array()參數問題

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\willammary\staff-admin\edit_notice.php on line 5 
+1

有數百個SO這個問題的複製品。你有沒有檢查他們? – Spudley

+1

除了明顯的SQL注入漏洞,缺少任何錯誤處理,使用舊的不推薦使用的MySQL擴展,id的價值是什麼? –

+1

@Spudley:一種...自我回答的問題。 –

回答

0

試試這個,

$uid = $_GET['id']; 
echo $sql = "select * from notice where id=".$uid; 
echo $result = mysql_query($sql); 
if($result === FALSE) { 
    die(mysql_error()); // error handling 
} 
$row = mysql_fetch_array($result); 
echo $row['headline']; 
echo $row['description']; 
echo $row['image']; 

另外,

$uid = $_GET['id']; 
echo $sql = "select * from notice where id=$uid"; 
echo $result = mysql_query($sql); 
if($result) { 
    $row = mysql_fetch_array($result); 
    echo $row['headline']; 
    echo $row['description']; 
    echo $row['image']; 
} 

或者

$uid = $_GET['id']; 
echo $sql = "select * from notice where id=$uid"; 
echo $result = mysql_query($sql) or die(mysql_error()); 
$row = mysql_fetch_array($result); 
echo $row['headline']; 
echo $row['description']; 
echo $row['image']; 

而且MySQL擴展deprecatedPHP 5.5.0的閱讀http://www.php.net/manual/en/intro.mysql.php

+0

也許你也可以解決SQL注入漏洞。 –