input 랜덤값 생성 if문

input 랜덤값 생성 if문

QA

input 랜덤값 생성 if문

본문

여분필드wr_1에

새글일때 임의의 값을 생성해서 저장시키고

수정일때 그값을 불러오려고 하는데 11번째줄

 echo "<input type='text' name='wr_1' value='<?=$write[wr_1]?>' id='wr_1' class='frm_input' maxlength='8' readonly>"

여기를 어떻게 기입해야 할까요?


        <?php if($w == '') { 
                function randomKey($length) { 
                $key = "";
                    $pool = array_merge(range(0, 9), range('A', 'Z')); // 숫자, 영문 소문자, 영문 대문자
                    for($i=0; $i < $length; $i++){
                        $key .= $pool[mt_rand(0, count($pool) - 1)];
                    }
                    return $key;
                    }
         $wr_1 = randomKey(8); // 8자리의 랜덤 문자열
         echo "<input type='text' name='wr_1' value='<?=$write[wr_1]?>' id='wr_1' class='frm_input' maxlength='8' readonly>"
        ?>
   
     
       
<?php } else if ($w == 'u') { ?>

       <input type="text" name="wr_1" value="<?=$write['wr_1']?>" id="wr_1" class="frm_input" maxlength="8" readonly>

            <?php } ?>
 

이 질문에 댓글 쓰기 :

답변 2

 echo "<input type='text' name='wr_1' value='{$write['wr_1]'}' id='wr_1' class='frm_input' maxlength='8' readonly>";

 

요렇게 변경해서 사용하세요

echo 문안에서 <? php문법을 사용하심 안되요

 

 

상단에


if ($w == '') {
function randomKey($length) { 
$key = "";
$pool = array_merge(range(0, 9), range('A', 'Z')); // 숫자, 영문 소문자, 영문 대문자
for($i=0; $i < $length; $i++){
$key .= $pool[mt_rand(0, count($pool) - 1)];
}
return $key;
}
$write['wr_1'] = randomKey(8); // 8자리의 랜덤 문자열
//echo $wr_1;
}

이렇게 wr_1에 랜덤값을 써주고

 

<input type="text" name="wr_1" value="<?=$write['wr_1']?>" id="wr_1" class="frm_input" maxlength="8" readonly>

 

그냥 이렇게 처리했습니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 32
QA 내용 검색
filter #echo ×

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT