2012-05-31 2 views
-1

가능한 중복 :
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in경고 : XAMPP htdocs를 WR header.php 라인 18

로 MYSQL_ASSOC()는 매개 변수 1 C에 주어진 자원 부울 것으로 예상

나는이 코드를 가지고있다.

<?//index.php 
if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly'); 


include('db.php');//include our database 
//connecting to the database 
$con = mysql_connect($dbhost, $dbusername, $dbpassword); 
//if we cant connect 
if (!$con) 
{ 
die ('could not connect to the database' . mysql_error()); 
} 
//if successfully connected then select db 
mysql_select_db ($dbtable, $con); 
//our query 
$result = mysql_query("SELECT * FROM header"); 
//fetch our result 
while($row = mysql_fetch_array($result)) //this is the line 18 
{ 
//if type is meta then.. 
if ($row['type'] === "meta") 
{ 
$meta .= "<meta name='".$row['name']."' content='".$row['content']."' />"; 
} 
//if type is title then.. 
elseif ($row['type'] === "title") 
{ 
$title = "<title>".$row['content']."</title>"; 
$title2 = "<div id='ti'>".$row['name']."</div>"; 
} 
//if type is favicon then.. 
elseif ($row['type'] === "favicon") 
{ 
$favicon = "<link rel='shortcut icon' href='".$row['content']."' />"; 
$imglogo = "<img class='imglogo' src='".$row['content']."' />"; 
} 
//if type is description then.. 
elseif ($row['type'] === "description") 
{ 
$des = "<div id='ti2'>".$row['content']."</div>"; 
} 

} 
mysql_close($con); 
?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<? echo $title; //line 50 ?> 
<? echo $favicon; //line 51 ?> 
<? echo $meta; //line 52 ?> 
<? echo (file_get_contents("cc.txt")); ?> 
</head> 

내가이 다음과 같은 오류를 가지고는, 경고 : \ XAMPP \ htdocs를 \ WR \ header.php 라인 (18)

주의 사항 :로 MYSQL_ASSOC()는 매개 변수 (1) C에 주어진 자원, 부울 될 것으로 예상 : 정의되지 않은 변수 : C의 제목 : \ XAMPP \ htdocs를 \ WR \ header.php 라인 50

공지 : 정의되지 않은 변수 : C에서 파비콘 : 라인 51 \ XAMPP \ htdocs를 \ WR \ header.php

알림 : 정의되지 않은 변수 : C : \ xampp \ htdocs \ wr \ header.php의 메타 line 52

오류 선은 코드를 따라 지정됩니다. 오류 선의 맨 위 코드를 참조하십시오.

나를 도울 수 있습니까? 미리 감사드립니다.

줄리버.

답변

0

오류가 아래의 라인 중 하나에 계속 이렇게 추가

$ result = mysql_query ("SELECT * FROM header") 또는 DIE (mysql_error());

2

아마도 SELECT가 성공하지 못했습니다. $result

if ($result === false) 

그렇다면, 당신은 mysql_error()와 오류 메시지를 얻을 수 있습니다

FALSE 인 경우 확인해야합니다.

+0

당신의 대답은 내 문제를 해결합니다. 당신에게 엄지 손가락을주었습니다. – youngdero

1

$ 결과를 mysql_fetch_array에 전달하기 전에 항상! == false로 확인해야합니다. 이는 쿼리에 실패한 경우 값이되기 때문이며, 이는 사용자의 상황에서 발생한 결과입니다. http://php.net/manual/en/function.mysql-query.php을 참조하십시오. 실패했을 경우 mysql_error()를 echo하여 무엇이 잘못되었는지 확인할 수 있습니다. http://php.net/manual/en/function.mysql-query.php에서

+0

당신은 저를 이겼습니다. W00d5t0ck –

0

: SELECT, SHOW, DESCRIBE를 들어

, 설명하고 다른 문 ( 결과 집합,는 mysql_query 반환은) 오류에 성공 자원 또는 FALSE를 반환합니다.

다른 SQL 문의 INSERT, UPDATE, DELETE, DROP 등의 경우 mysql_query()는 성공시 TRUE를, 오류시 FALSE를 반환합니다.

mysql_query()도 실패하고 사용자가 쿼리에서 참조하는 테이블에 액세스 할 수있는 권한이 없으면 FALSE를 반환합니다.

결과를 계속 처리하기 전에 항상 부울 값이 아닌지 확인해야합니다 (예 :!(($의 DBTABLE, $ 콘) OR (mysql_error를을 DIE))

반환 mysql_select_db;) == FALSE

관련 문제