2012-05-22 13 views
-2

내가 인터넷에서 검색하고 내 코드와 함께 놀아 시간을 보냈어요하지만이 오류 메시지가 무엇입니까 왜 여전히 알아낼 수 없습니다에서 함수의 반환 값을 사용할 수 없습니다.치명적인 오류 : 쓰기 컨텍스트

} else { 
     if (!empty($errors) && nexus_error($nexus)==false) { 
      $message = "There were" . count($errors) . " errors in the form."; 
     } if (!empty($errors) && nexus_error($nexus)) { 
      $message = "There were" . count($errors) . " errors in the form."; 
      $message .= "A user with the username" . $nexus . " already exists in the database."; 
     } if (empty($errors) && nexus_error($nexus)) { //***this line causes the error 
      $message = "A user with the username" . $nexus . " already exists in the database."; 
     } 
    } 

함수 nexus_error, 그런데, 아래 정의 : 어떤 도움이 좋을 것

function nexus_error($sel_nexus) { 
    global $connection; 
    $query = "SELECT * FROM person WHERE nexus={$sel_nexus}"; 
    $result_set = mysql_query($query, $connection); 
    confirm_query($result_set); 
    if (count(mysql_fetch_array($result_set)) != 0) { 
     return true; // bad 
    } else { 
     return false; 
    } 
} 

여기 내 코드에서 발췌 한 것입니다. 시간에 대한 감사합니다 :)

+0

[검색] (http://www.google.com/search?q=Fatal+error%3A+Can't+use+function+return+value+in+write+context)을 시도 했습니까?)? 또는 Stack Overflow가 질문을 작곡했을 때 제안했던 관련 ** 질문 (이 페이지의 오른쪽에 다시 표시됨)을 살펴보십시오. 구글의 최고 히트 [이] (http://stackoverflow.com/questions/1532693/weird-php-error-cant-use-function-return-value-in-write-context) 스택 오버플로 질문입니다. – eggyal

+0

여기서는 confirm_query ($ result_setuery)의 함수 정의입니까? – jugnu

답변

0

은 새미는 문제의 라인 대신 계산의 mysql_num_rows()입니다 반환 된 결과의 양을 계산하는 적절한 방법 if (count(mysql_fetch_array($result_set)) != 0) {

입니다 말했듯이, 당신의 라인은 단순히이 될 수있다 코드는 nexus_error($nexus)는 지난 if 문 (즉이 불필요한 쿼리의)를 통해 필터링하는 경우이 같은 변수에 3 번 호출 될 수있다, 그래서 같은 리팩토링을 고려한다는 점에서 현재 비효율적이다 :

$nexusError = nexus_error($nexus); 
} else { 
    if (!empty($errors) && $nexusError ==false) { 
     $message = "There were" . count($errors) . " errors in the form."; 
    } if (!empty($errors) && $nexusError) { 
     $message = "There were" . count($errors) . " errors in the form."; 
     $message .= "A user with the username" . $nexus . " already exists in the database."; 
    } if (empty($errors) && $nexusError) { //***this line causes the error 
     $message = "A user with the username" . $nexus . " already exists in the database."; 
    } 
} 
+0

안녕, 고마워. 나는 너의 제안을 (둘 다) 취했다. 그러나 오류는 계속 발생합니다. 오류 로그에이 오류가 하나만 표시됩니다. 그것은 내가 코드의 전체 블록을 주석 경우에도, 이상해, 난 여전히 같은 오류가 ... – nv39

+0

@NVidovic는이 경우에 잘못된 코드는 우리에게 보낸! – Dunhamzzz

+0

그 뜻이 확실하지 않습니다. 오류가 게시하지 않은 코드의 다른 부분에 있음을 의미합니까? – nv39

1
if (count(mysql_fetch_array($result_set)) != 0) 

당신은 할 수 없습니다 count() 함수의 반환 값. 이전에 변수에 저장해야합니다. 또한,

if (mysql_num_rows($result_set) != 0) { 

:

+0

안녕하세요, 감사합니다. 나는 그것을 고쳤지 만 문제는 여전히 불행히도 남아있다. – nv39

+0

왜 mysql_num_rows()를 사용하지 않을까?! – Dunhamzzz

+0

@NVidovic 전체 스택 추적을 표시 할 수 있습니까? S –