2012-04-25 4 views
-2
주어진

가능한 중복 : 내 스크립트를 실행하면
PHP Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given로 MYSQL_ASSOC()는 매개 변수 (1) 자원이 될 것으로 예상, 부울

나는 이러한 오류가 계속 나는 알아낼 수 없습니다 지금 당장 PHP가 필요없는 것처럼 표시되지 않기 때문에 수정해야 할 사항이 있습니다.

여기 제가받는 오류가 있습니다.

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/WordOfMouth/root/pages/profile_page/profile_page.php on line 38 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/WordOfMouth/root/pages/profile_page/profile_page.php on line 44 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/WordOfMouth/root/pages/profile_page/profile_page.php on line 136 

도움이 될 것입니다. 다음 두 줄의 코드에서

<?php 
include_once("../../mysql_server/checkuserlog.php"); 
?> 
<?php 
// Now let's initialize vars to be printed to page in the HTML section so our script does not return errors 
// they must be initialized in some server environments 
$id = ""; 
$firstname = ""; 
$middlename = ""; 
$lastname = ""; 
$country = ""; 
$state = ""; 
$city = ""; 
$zip = ""; 
$bio_body = ""; 
$bio_body = ""; 
$user_pic = ""; 
$blabberDisplayList = ""; 
// If coming from category page 
if ($_GET['id']) { 

$id = $_GET['id']; 

} else if (isset($_SESSION['id'])) { 

$id = $_SESSION['id']; 

} else { 

    include_once "../home_page/home_page.php"; 

    exit(); 
} 

$id = mysql_real_escape_string($id); 
$sql = mysql_query("SELECT * FROM myMembers WHERE id='$id' LIMIT 1"); 

if (mysql_num_rows($sql) === 0) { // evaluate the count 
echo("ERROR"); 
    exit(); 
} 
// ------- END MAKE SURE PERSON EXISTS IN DATABASE --------- 
// Make sure this person a visitor is trying to view actually exists 
while($row = mysql_fetch_array($sql)){ 
$firstname = $row["firstname"]; 
$lastname = $row["lastname"]; 
$country = $row["country"]; 
$state = $row["state"]; 
$city = $row["city"]; 
$sign_up_date = $row["sign_up_date"]; 
    $sign_up_date = strftime("%b %d, %Y", strtotime($sign_up_date)); 
$last_log_date = $row["last_log_date"]; 
    $last_log_date = strftime("%b %d, %Y", strtotime($last_log_date)); 
$bio_body = $row["bio_body"]; 
$bio_body = str_replace("&amp;#39;", "'", $bio_body); 
$bio_body = stripslashes($bio_body); 
$website = $row["website"]; 
$youtube = $row["youtube"]; 
$facebook = $row["facebook"]; 
$twitter = $row["twitter"]; 
$friend_array = $row["friend_array"]; 
/////// Mechanism to Display Pic. See if they have uploaded a pic or not  ////////////////////////// 
$check_pic = "../../members/$id/image01.jpg"; 
$default_pic = "../../members/0/image01.jpg"; 
if (file_exists($check_pic)) { 
$user_pic = "<img src=\"$check_pic?$cacheBuster\" width=\"218px\" />"; 
} else { 
$user_pic = "<img src=\"$default_pic\" width=\"218px\" />"; 
} 

} 

?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html" /> 
<meta name="Description" content="Profile for <?php echo "$username"; ?>" /> 
<meta name="Keywords" content="<?php echo "$username, $city, $state, $country"; ?>" /> 
<meta name="rating" content="General" /> 
<meta name="ROBOTS" content="All" /> 
<title>Profile Page</title> 
<link href="../../style.css" rel="stylesheet" type="text/css" /> 
<link rel="icon" href="#" type="image/x-icon" /> <!-- INSERT ICON --> 
<link rel="shortcut icon" href="#" type="image/x-icon" /> <!-- AND HERE --> 
<script src="../../jquery-1.4.2.js" type="text/javascript"></script> 

</head> 
<body> 
<div class="wrapOverall"> 
<?php include_once '../../templates/decide_header.php'; ?> 
<table width="900" border="0" style="background-color:#F2F2F2; border:#999 1px solid;" align="center" cellpadding="0" cellspacing="0"> 
    <tr> 
    <td width="738"><br /> 
     <table width="90%" border="0" align="center" cellpadding="6"> 
     <tr> 
     <td width="48%" valign="top"> 
     <?php print "$firstname $lastname"; ?> 
     <br /> 
     <?php print "$user_pic"; ?> 
     <br /> 
     Member Since: <?php print "$sign_up_date"; ?> 
     <br /> 
     <?php print "$youtubeChannel"; ?> 
     </td> 
     <td width="52%" valign="top"> 
     <br /> 
     <strong><u><?php print "$firstname $lastname"; ?>'s Blabs:</u></strong> 
     <br /> 
     <?php print "$the_blab_form"; ?> 
     <div style="width:100%; height:180px; overflow:auto; overflow-x:hidden;"> 
     <?php print "$blabberDisplayList"; ?> 
     </div> 
     <br /> 
     <br /> 
     <strong><u><?php print "$firstname $lastname"; ?>'s Location Details:</u></strong> 
    <br /> 
    <?php print "$city"; ?> &bull; <?php print "$state"; ?> &bull; <?php print "$country"; ?> 
    <br /> 
    <br /> 
    <strong><u>About <?php print "$firstname $lastname"; ?></u></strong> 
    <br /> 
    <?php print "$bio_body"; ?> 
    <br /> 


    </td> 
    </tr> 
    <tr> 
    <td colspan="2" valign="top">&nbsp;</td> 
    </tr> 
    </table> 
    <p><br /> 
    <br /> 
    </p></td> 
<td width="160" valign="top"><?php include_once "../../templates/right_AD_template.php"; ? ></td> 
    </tr> 
</table> 
<?php include_once '../../templates/footer_template.php'; ?> 
</div> <!-- END wrapOverall --> 
</body> 
</html> 
+0

분명히 문제는 우리가 보여준 코드가 아니라 mysql_ * 함수를 사용하는 다른 코드에서입니다. –

+0

오른쪽에있는 관련 질문을보십시오. 이럴 수가. 나는 그들이 질문을 쓰는 동안 나온 것이라고 확신한다. – webbiedave

+1

도움이된다면 믿을 수 없을 것입니다 *, 왜 물어보십시오? :) –

답변

1

:

mysql_query이 실패하면
$sql = mysql_query("SELECT * FROM myMembers WHERE id='$id' LIMIT 1"); 
if (mysql_num_rows($sql) === 0) { // evaluate the count 

, 당신은 mysql_num_rows()에 전달 될 수있는 실행 가능한 resource이 없습니다.

먼저 쿼리가 실제로 실행 있는지 확인해야합니다 :

$sql = mysql_query("SELECT * FROM myMembers WHERE id='$id' LIMIT 1"); 
if (!$sql) { 
    // query failed 
    echo "Query failed: " . mysql_error(); 
} else { 
    $num_rows = mysql_num_rows($sql); 
    // rest of your code 
} 

당신이 ===을 가지고 있기 때문에이 잘못된 값으로 호출 된 이후에 널 (null)이 함수에 의해 반환 되었기 때문에, 표현 mysql_num_rows($sql) === 0 사실 평가합니다. 따라서 잘못된 리소스로 mysql_fetch_array이 호출 된 것과 동일한 문제가 발생합니다.

주요 단서는 mysql_num_rows() expects parameter 1 to be resource, boolean given입니다.

리소스를 예상하지만 사용할 수없는 부울이 지정되었습니다. 따라서 전달할 변수의 값과 리소스 대신 bool (이 경우 쿼리가 실패하기 때문에) 인 이유를 조사 할 수 있습니다.

+0

그것은 오류가 "No Database Selected"라고 말하지만 전체 connect_to_mysql을 디버깅했으며 자체적으로 연결하고 다른 모든 페이지에서 작업하는 것처럼 보입니다. 내가 데이터베이스에서 선택을 해제하게 만드는 일이 있습니까? –

+0

게시 한 코드에서 볼 수있는 내용이 없습니다. 선택을 취소하면 포함 항목 중 하나에 코드가 있거나 연결을 할당하는 변수가 덮어 쓰기됩니다 (할당하는 경우). – drew010

관련 문제