2013-11-20 1 views
0

메신저가 될 것으로 기대하고있다. 다른 텍스트 필드도 를 htmlentities()는 매개 변수 1 문자열을 텍스트 필드에 데이터베이스에서 데이터를 얻으려고 노력


Warning: htmlentities() expects parameter 1 to be string, resource given in C:\xampp\htdocs\CashFlow\febprev.php on line 116

난 그냥 시험이 코딩을 사용

<input type="text" name="febbonus" size="11" placeholder="0" value="<?php if(@$fbonus){echo (@$fbonus);} ?>"> 

그리고 난이 오류가있어 :

Resource id #7

어떤 아이디어? 당신은 지금이

$fothers=mysql_query($fothersq); 

를 실행하기 때문에

+2

하십시오 [RTFM을'mysql_query' 위해 (http://php.net/mysql_query)과 그 예. – deceze

+2

'@'기호를 사용하지 않는 것이 좋습니다. 그것은 당신을 이미 혼란스럽게합니다. –

답변

2

오류가 문제가 정확히 무엇을 말하고있다 :

Warning: htmlentities() expects parameter 1 to be string, resource given in C:\xampp\htdocs\CashFlow\febprev.php on line 116

그리고이 : 이러한 오류의

Resource id #7

둘은 mysql_query가 리소스를 반환 함을 말하고있다. 이 시점에서는 문자열이 아닙니다. 해당 리소스 &을 처리하려면 필요합니다. 이 시도.

$fothersq=("SELECT others FROM january"); 
$fothers=mysql_query($fothersq); 
while ($row = mysql_fetch_assoc($fothers)) { 
    echo sprintf('<input type="text" placeholder="0" name="febothers" size="11" value="%s">', (!empty($row['others'] ? htmlentities($row['others']) : ''))); 
} 

또한 제시 한 코드가 바로 PHP 또는 HTML 또는 두 가지의 혼합으로 거의 의미가 있기 때문에 내가 echo<input type="text"> HTML 요소를 배치 있습니다.

편집 :

$fothersq=("SELECT others FROM january"); 
$result=mysql_query($fothersq); 
while ($row = mysql_fetch_assoc($result)) { 
    $fothers = ''; 
    if (!empty($row['others']) { 
    $fothers = htmlentities($row['others']); 
    } 
    echo '<input type="text" placeholder="0" name="febothers" size="11" value="' . $fothers . '">'; 
} 
:
원래 포스터가 삼항 연산자에 의해 혼동 될 수 있다는 의견을 바탕으로, 여기에 있지만 약간 간단한 방법으로, 같은 목표를 달성 할 내 대답의 수정 된 버전입니다
+1

IMO, sprintf 및 삼항 연산자는이 기본 문제를 겪은 개발자에게이 솔루션을 더욱 복잡하게 만듭니다. – vonUbisch

+0

좋은 지적. 비교/대조 할 원래 솔루션에 추가 변형을 추가했습니다. – JakeGould

+0

입력 해 주셔서 감사합니다. 나는 이것을 통해 내가 원하는 것을 얻었습니다. $ fothersq = ("SELECT others FROM january"); $ fothers = mysql_query ($ fothersq); $ row = mysql_fetch_array ($ fothers); user2971776

1

$fothers 문자열되지 않습니다. resource

$fothers을 문자열로 예상하는 htmlentities()으로 전달합니다.

1

포인트는 수정합니다 :

  • 를 htmlentities() 함수는 귀하의 경우 귀하의 통과 자원에 문자열 곳을 예상하고 HTML entities.So 문자로 변환합니다.

  • 아무 것도 가져 오지 않았기 때문에 Resource id #7이 표시됩니다. 실행 후 mysql_fetch_array을 사용하여 행을 페치합니다.


이 시도 :

$fothersq=("SELECT others FROM january"); 
$fothers=mysql_query($fothersq); 
while ($fetch = mysql_fetch_array($fothers)) { 
?> 
<input type="text" name="febothers" size="11" value="<?php echo (isset($fetch[0])) ? htmlentities("$fetch[0]") : ''?>"> 
<?php 
} 
관련 문제