여분필드 추가 관련
본문
해당 게시글 활용해서 여분필드 21개까지 추가했는데
write페이지에서 잘 나오는데 글을 작성하면 올바른 방법으로 이용해달라는 메세지가 뜹니다.
아마 여분필드 추가가 적용이 안된것같습니다.
bbs/write_update.php
$sql = " insert into $write_table 부분과
$sql = " update {$write_table} 부분 하단에 wr_11= '{$wr_11}' ~ wr_21= '{$wr_21}' 추가했고
bbs/move_update.php
$sql = " insert into $move_write_table 부분에 추가했습니다.
insert 와 update 부분 총 3군데 추가했는데요. 여분필드 추가 전에는 작성이 됐었는데
여분필드 추가 후에 오류가 나네요..
또 혹시 db에서 해당 필드가 추가된걸 어디서 확인해볼 수 있는지 알 수 있을까요?
답변 3
bbs/move_update.php
bbs/write_update.php
는 원본 그대로 사용하세요.
해당 게시판(skin/board/basic/write_update.skin.php를 생성하세요-아래코드대로)
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
$sql = " update $write_table
set wr_11 = '$wr_11',
wr_12 = '$wr_12',
wr_13 = '$wr_13',
wr_14 = '$wr_14',
wr_15 = '$wr_15',
wr_16 = '$wr_16',
wr_17 = '$wr_17',
wr_18 = '$wr_18',
wr_19 = '$wr_19',
wr_20 = '$wr_20',
wr_20 = '$wr_21'
where wr_id = '$wr_id' ";
sql_query($sql);
}
여분필드 추가파일(아래) wr-add.php생성하여 아무데나올리고 실행하세요.
<?php
include_once('./_common.php');
include_once(G5_PATH.'/head.php');
$mmm = explode('/wr-add.php',$_SERVER['PHP_SELF'])[0];
if ($is_admin == 'super') {
goto start;
} elseif (!$is_member) {
alert('여분필드 추가/삭제는 관리자 로그인이 필요합니다.',G5_URL."/bbs/login.php?wr_id='.$qstr.'&url='$mmm/wr-add.php'");
} elseif (!$is_admin == 'super' && $is_member) {
alert('여분필드 추가/삭제는 관리자 로그인이 필요합니다.', '/');
}
goto end;
start:;
$g5['title'] = "게시판 여분필드 추가";
$frm_submit = '<div class="btn_confirm01 btn_confirm">
<input type="submit" value="확인" class="btn_submit" accesskey="s">
'.PHP_EOL;
$frm_submit .= '</div>';
$sql = "select bo_table, bo_subject from {$g5['board_table']} order by gr_id";
$ff = sql_fetch($sql);
$first_tb = $ff['bo_table'];
if($tab == "") $tab = $first_tb;
$db_table = $g5['write_prefix'].$tab;
$sql = "show full columns from {$db_table} where field REGEXP 'wr_[0-9]' ";
$query = sql_query($sql);
$count = mysqli_num_rows($query);
for($i=0;$i<$count;$i++) {
$finfo[] = mysqli_fetch_assoc($query);
}
if ($is_admin =='super') {
if($wr_start && $wr_end){
if($board_id){
$board_qry = " where bo_table = '{$board_id}' ";
}
$sql = "select * from {$g5['board_table']}".$board_qry;
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {
$write_table = $g5['write_prefix'] . $row['bo_table'];
for ($k=$wr_start; $k<=$wr_end; $k++) {
$cols = sql_fetch(" SHOW COLUMNS FROM {$write_table} LIKE 'wr_{$k}' ");
if(!isset($cols)) {
sql_query(" ALTER TABLE `{$write_table}` ADD `wr_{$k}` varchar(255) NOT NULL DEFAULT '' ");
}
}
}
alert('여분필드를 추가했습니다.', $mmm.'/wr-add.php?tab='.$tab);
}
} else if($is_member) {
alert('여분필드 추가/삭제는 관리자 로그인이 필요합니다.', '/');
} else {
goto_url(G5_BBS_URL.'/login.php?wr_id='.$wr_id.$qstr.'&url='.$mmm.'/wr-add.php');
}
?>
<div class="wr_fo">
<h2 id="h_title"><span>게시판 여분필드 추가 삭제</span></h2>
<div class="wr_form_box">
<form name="colwrite" id="colwrite" action="<?php echo $action_url ?>" method="post" enctype="multipart/form-data" autocomplete="off" style="width:100%" onSubmit="return form_submit()">
<div class="tbl_frm01 tbl_wrap">
<table>
<tr>
<?php
for($i = 1; $i < $nb+2; $i++) {
$ii = 'wr_'.$i;
if(!$w){
$qq=sql_fetch(" SHOW COLUMNS FROM ".G5_TABLE_PREFIX."write_$tab like '$ii' ");
if($qq['Type']=='varchar(255)')
$nb = explode("wr_", $ii)[1]+1;
}
}
?>
<th scope="row"><label for="board_id">게시판 ID</label></th>
<td>
<input type="text" style="background:#addeee;text-align:center;margin-top:-3px" name="board_id" value='<?php echo $tab?>' id="board_id" class="frm_input" size="15" maxlength="20" placeholder="전체게시판"></input><tho scope="row"><label for="">Table</label></tho><input type="text" style="background:none;margin-left:10px;text-align:center;margin-top:-3px" name="" value="" id="" class="frm_input1" size="15" maxlength="20" disabled></input><?php echo '<lij id="resultt">'.$tab.'</lij>';?><span><a class="prism-btn" href="#open-modal">도움말</a></span>
<!-- 코드 하이라이트 모달시작 -->
<div id="open-modal" class="modal-window">
<div>
<a href="#modal-close" title="닫 기" class="modal-close">닫 기</a>
<h1>여분필드 추가/삭제 방법</h1>
<ol type="I">
<li>삭제는 게시판별 1개씩 삭제 하세요.</li>
<li>게시판ID를 지우면 전체게시판에 추가됩니다.</li>
<li>bbs/write_update.php "wr_" 추가된 부분 추가 (2곳)</li>
wr_11 = '$wr_11',<br>
wr_12 = '$wr_12' ";<br>
sql_query($sql);<br><br>
<li>bbs/move_update.php "wr_" 추가된 부분 추가</li>
wr_11 = '".addslashes($row2['wr_11'])."',<br>
wr_12 = '".addslashes($row2['wr_12'])."' ";<br>
sql_query($sql);<br><br>
<li>bbs생략시 skin/board/abc?/write_update.skin.php 추가</li>
$sql = " update $write_table<br>
set<br> wr_11 = '$wr_11',<br>
wr_12 = '$wr_12'<br>
where wr_id = '$wr_id' ";<br>
sql_query($sql);<br><br>
<li>현재 <span class="namepen"><?php echo $tab?></span>의 여분필드는 <span class="namepen"><?php echo $nb-1?></span>번 까지 사용중 입니다.</li>
<li>table 보기/선택
<select id="sels" class="nfor" onchange="if(this.value) location.href=(this.value)">
<?php
$sql = " select bo_table, bo_subject from $g5[board_table] order by gr_id, bo_table ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {
?>
<option value="<?php echo $mmm?>/wr-add.php?tab=<?php echo $row['bo_table']?>"<?php echo get_selected($row['bo_table'], $tab);?>><?php echo $row['bo_subject'];?></option>
<?php } ?>
</select>
</li>
</ol>
</div>
</div>
<!-- 코드 하이라이트 모달끝 -->
</td>
</tr>
<tr>
<th scope="row"><label for="wr_start">wr_시작번호</label></th>
<td><input type="text" style="background:#addeee;text-align:center;margin-top:-3px" name="wr_start" value="<?php echo $nb?>" id="wr_start" class="frm_input" size="15" maxlength="20"></input><tho scope="row"><label for="wr_del">wr_삭제번호</label></tho><input type="text" name="wr_del" value="" id="wr_del" class="frm_input1 l6" size="15" maxlength="20" disabled></input><?php $nc=$nb-1;echo '<lij>'.$nc.'</lij>';?><span class="sdl" id="del_last_column" del_num="<?php echo $nb-1;?>">삭 제<span></td>
</tr>
<tr>
<th scope="row"><label for="wr_end">wr_끝번호</label></th>
<td><input type="text" onchange='printName()' style="background:#addeee;text-align:center" name="wr_end" value="" id="wr_end" class="frm_input" size="15" maxlength="3"></input><tho scope="row"><label for=""></label></tho><input type="text" name="" value="" id="" class="frm_input1 l6" size="15" maxlength="20" disabled></input><?php echo '<lij id="resulta"></lij>';?><?php echo $echo; ?><input type="submit" name="add_column" value="추 가" id="btn-submit" accesskey="s" class="wr_form_btn" disabled></input></td>
</tr>
</table>
</div>
</form>
<div class="l3">게시판 여분필드 확인</div>
</div>
<div class="l2">
<h2 id="e_title"><span>
<?php
$nbd = $nb-1;
$sql = " select bo_table, bo_subject from $g5[board_table] order by gr_id, bo_table ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {
$tls = $row['bo_table'];
for($k = 1; $k < $nb; $k++) {
$ii = 'wr_'.$k;
if(!$w){
$qq=sql_fetch(" SHOW COLUMNS FROM ".G5_TABLE_PREFIX."write_$tls like '$ii' ");
if($qq['Type']=='varchar(255)')
$mb = explode("wr_", $ii)[1]+1;
}
}
$nbb = $mb-1;
if ($nbb>$nbc)$nbc=$nbb;
if ($nbb<$nbd)$nbd=$nbb;
echo '<a href='.$_SERVER['PHP_SELF'].'?tab='.$tls.'>'.$tls.'<ls style="font-size:9px;color:#0f0">('.$nbb.')</ls></a>, ';
}
for($b = 10;$b<$nb;$b++){
$find = 'wr_'.$b;
$arr = file(G5_BBS_PATH.'/move_update.php');
$arr1 = file(G5_BBS_PATH.'/write_update.php');
foreach($arr as $line){
$str = iconv("EUC-KR","UTF-8",$line);
if(strpos($str,$find) !== false) preg_match("#wr_(.+?) #", $str, $str3);
}
foreach($arr1 as $line){
$str = iconv("EUC-KR","UTF-8",$line);
if(strpos($str,$find) !== false) preg_match("#wr_(.+?) #", $str, $str4);
}
}
echo '<br>';
if($nbd !== $nbc) echo '<ls style="border:1px solid #f00;padding:5px;font-size:9px;color:#f00">[여분필드 : '.$nbd.' ~ '.$nbc.']</ls>';
if(strcmp($nbc, $str3[1]) || $nbc !== intval($str3[1])) echo '<ls style="border:1px solid #f00;padding:5px;font-size:9px;color:#f00"> /bbs/move_update.php가 wr_'.$str3[1].'입니다.</ls>';
if(strcmp($nbc, explode('=',$str4[1])[0]) || $nbc !== intval($str4[1])) echo '<ls style="border:1px solid #f00;padding:5px;font-size:9px;color:#f00"> /bbs/write_update.php가 wr_'.$str4[1].'입니다.</ls>';
?>
<!--?php if($nbd !== $nbc || $nbc !== intval($str3[1])){ ?><div class="l4">여분필드가 모두 동일하하지 않습니다.</div><!?php } ?-->
</span></h2></div>
</div>
<?php if(is_mobile()){ ?><div class="wr_fx l4">휴대폰을 가로모드로 하세요.</div><?php } ?>
<script>
$(document).on('change', '#wr_end', function() {
var val= $(this).val();
if(val < <?php echo $nb?> && val !== '' || val > 999 && val !== '') {
alert('<?php echo $nb?>~999 범위로 입력해 주십시오.');
$(this).val('');
var flag = true;
flag = $(this).val().length > 1 ? false : true;
$("#btn-submit").prop("disabled", flag);
const namee = document.getElementById('board_id').value;
if(namee == ''){document.getElementById("resultt").innerText = '';}
const namea = document.getElementById('wr_end').value;
document.getElementById("resulta").innerText = '';
} else {
var flag = true;
flag = $(this).val().length > 1 ? false : true;
$("#btn-submit").prop("disabled", flag);
const namee = document.getElementById('board_id').value;
if(namee == ''){document.getElementById("resultt").innerText = '전체게시판';
}else{
document.getElementById("resultt").innerText = namee;
}
const namea = document.getElementById('wr_end').value;
document.getElementById("resulta").innerText = namea;
if(val !== '') {
alert(namee + '[wr_<?php echo $nb?>]부터 [wr_' + namea + '] 추가가 맞습니까?');
}
}
});
$(document).on('change', '#board_id', function() {
var val= $(this).val();
if(val == '') {
var flag = true;
flag = $(this).val().length > 1 ? false : true;
$("#btn-submit").prop("disabled", flag);
const namee = document.getElementById('board_id').value;
if(namee == ''){document.getElementById("resultt").innerText = '전체게시판';
}else{
document.getElementById("resultt").innerText = namee;
}
}
});
$(document).on("focusout", "input[name^=wr_start]", function() {
var val= $(this).val();
if(val < <?php echo $nb?>|val > <?php echo $nb?>) {
alert('<?php echo $nb?>로 입력해 주십시오.');
$(this).val('<?php echo $nb?>');
}
});
$(document).on("keyup", "input[name^=board_id]", function() {
var val= $(this).val();
if(val.replace(/[0]/g, "").length > 0) {
alert('도움말/여분필드 확인에서 선택하여 주십시오.');
location.reload();
// $(this).val('');
}
});
$(document).on("keyup", "input[name^=wr_end],input[name^=wr_start]", function() {
var val= $(this).val();
if(val.replace(/[0-9]/g, "").length > 0) {
alert('숫자만 입력해 주십시오.');
$(this).val('');
}
});
function form_submit(){
if(val.replace(/[0-9]/g, "").length > 0) {
var check_submit=confirm('추가 하시겠습니까?');
return check_submit;
}
}
</script>
<style>
/*modal prism*/
.prism-btn {font-weight: bold;border:1px solid #f00;border-radius: 3px;font-weight:800;color:#eee;padding:2px 17px;line-height:30px;cursor:pointer;float: right}
.prism-btn:hover {color:#fa0;background:#66cdaa}
.modal-window {position: fixed;top:0;right:0;bottom:0;left:0;z-index: 999;opacity:0;pointer-events:none;-webkit-transition: all 0.3s;-moz-transition: all 0.3s;transition: all 0.3s;}
.modal-window:target {opacity: 1;pointer-events: auto}
.modal-window header {font-weight: bold}
.modal-close:hover {background:#000;color:#fff;font-weight: bold}
.modal-window h1 {font-size: 150%;text-align:center;margin: -15px 0 15px}
.nfor{background:#008be9;padding-left:10px;border:1px solid #d0d3db;color:#eee;outline:none}
.tabl{margin-right:5px;padding:1px;line-height:30px;border:1px solid #d0d3db}
.tablt{margin:-10px 0}
.namepen {width: fit-content;padding: 0 0.25%;position: relative;color:#000;z-index: 1}
.namepen::after {position: absolute;display: block;content: '\00a0';width: 100%;left: 0;right: 0;top: 0%;height: 100%;color:#000;background-color:#ffd472;transform: skew(-0deg);z-index: -1}
.wr_form_btn:disabled {border:1px solid #f00;opacity:.5;background:none;color:none;cursor:default;float: right}
.frm_input1{height:40px;border:1px solid rgba(0,0,0,.01);vertical-align:middle;border-radius:3px;padding:5px;-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);}
.sdl{border:1px solid #f00;display:inline-block;color:#c1e0ff;margin-left:0px;padding:8px 20px;opacity:.5;float: right}
.sdl{border:1px solid #f00}
.sdl:hover{opacity:1;display:inline-block;cursor:pointer;margin-left:0px;background:#f00;padding:8px 20px;font-weight:bold;color:#fff}
.tbl_wrap {margin:0 0px 10px}
.tbl_wrap table{background:none;border:1px solid #d0d3db}
.tbl_frm01 th{background:none;width:100px}
body{background:linear-gradient(to right, #41f, #490e60);**#41f;**#212020}
#e_title {font-size:1em;margin-top:-15px;color:#fff;font-weight:bold;background:linear-gradient(to right, #490e60, #41f);**#212020;**#41f}
#e_title span {display:block;line-height:30px;padding:10px}
.l2{display:none;cursor:pointer}
.l2 a{color:#eee}
.l3{width:100%;height:70px;text-align:center;font-size:1em;font-weight:bold;color:#fff;cursor:pointer}
.l4{width:100%;text-align:center;font-size:2em;font-weight:bold;color:#fff;padding:100px 0}
.l6{background:none;margin-left:10px;text-align:center;color:#f00;margin-top:-3px}
tr {color:#eee;background:linear-gradient(to right, #490e60, #41f);**#212020;**#41f}
<?php if(!is_mobile()){ ?>
#h_title {font-size:1.333em;margin-top:20px;color:#fff;font-weight:bold;background:linear-gradient(to right, #490e60, #41f);**#212020;**#41f;margin:0 auto;width:560px}
#h_title span {display:block;line-height:30px;padding:10px}
.wr_form_box{padding:20px 0;margin:0 auto;width:560px}
.modal-window>div {width: 460px;position: relative;cursor:move;margin: 5% auto;padding: 2rem;line-height:20px;background: #0099ff;color: #fff;background-color: #0099ff;background-image: linear-gradient(62deg, #0099ff 0%, #0066aa 100%)}
.modal-close {color: #aaa;line-height: 50px;font-size: 80%;position: absolute;right: 0;text-align: center;top: 0;width: 70px;text-decoration: none}
lij {margin-left:-125px;padding:15px;color:#f00}
.wr_form_btn{display:inline-block;margin-left:0px;font-weight:bold;padding:8px 20px;color:#fff;background:#f00;border:1px solid rgba(0,0,0,.01);float: right}
.tbl_frm01 tho {display:inline-block;margin:-7px 0 -7px 10px;width:100px;padding:10px 15px;text-align:right}
<?php } else { ?>
@media screen and (min-width: 640px) {
.wr_fo{display:block}
.wr_fx{display:none}
}
@media screen and (max-width: 639px) {
.wr_fo{display:none}
.wr_fx{display:block}
}
#h_title {font-size:1.333em;margin-top:20px;color:#fff;font-weight:bold;background:linear-gradient(to right, #490e60, #41f);**#212020;**#41f;margin:0 auto;width:640px}
#h_title span {display:block;line-height:30px;padding:10px}
.wr_form_box{padding:20px 0;margin:0 auto;width:640px}
.modal-window>div {width: 230px;position: relative;cursor:move;margin: 5% auto;padding: 2rem;line-height:20px;background: #0099ff;color: #fff;background-color: #0099ff;background-image: linear-gradient(62deg, #0099ff 0%, #0066aa 100%)}
.modal-close {color: #aaa;line-height: 50px;font-size: 80%;position: absolute;right: 0;text-align: center;top: 0;width: 35px;text-decoration: none}
lij {position:absolute;margin-left:-125px;padding:10px;color:#f00}
.wr_form_btn{display:inline-block;margin-left:10px;font-weight:bold;padding:8px 20px;color:#fff;background:#f00;border:0;float:right}
.tbl_frm01 tho {display:inline-block;margin:-7px 0 -7px 10px;width:100px;padding:10px 15px;text-align:right}
<?php } ?>
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".modal-window").draggable();
});
$("#del_last_column").click(function(){
if(confirm('<?php echo $tab ?>의 wr_<?php echo $nb-1 ?>을 삭제 하시겠습니까? wr_<?php echo $nb-1 ?>의 자료가 삭제됩니다.')){
var bo_table = '<?php echo $tab ?>';
var del_num = $(this).attr("del_num");
$.ajax({
type:"POST",
cache: false,
url:'<?php echo $mmm?>/wr-add-update.php',
data: {bo_table:bo_table, wr_id:del_num},
dataType: "html",
success:function(rt_value){
alert(rt_value);
},
error:function(){
alert("error!");
},
complete:function(){
document.location.reload();
}
});
}
});
$(document).ready(function () {
$(":checked,:selected").css("border", "2px solid red");
$(":selected").css("background", "blue");
});
$('.l2,.l3').click(function(){
var state = $('.l3').css('display');
if(state == 'none'){
$('.l3').show();
$('.l2').hide();
}else{
$('.l3').hide();
$('.l2').show();
}
});
</script>
<?php
end:;
include_once(G5_PATH.'/tail.php');
wr-add-update.php
<?php
include_once('./_common.php');
if($is_admin !== "super") {
echo "error";
exit;
}
$bo_table = $_POST['bo_table'];
$wr_id = "wr_".$_POST['wr_id'];
$tb_name = $g5['write_prefix'].$bo_table;
$sql = "ALTER TABLE `{$tb_name}` DROP `{$wr_id}`";
$query = sql_query($sql, false);
if(!$query) {
echo "쿼리에러";
} else {
echo "삭제를 완료 하였습니다.";
}
phpmyadmin 으로 정상적으로 해당 컬럼이 추가되었는지 채크해보세요.
글 업데이트시 "올바른 방법으로 이용해 주세요" 문구는
submit할때 글쓰기 토큰이 생성 오류일 수 있습니다.
그누보드는 기본적으로 여분필드 값을 체크하지 않기 때문에 "올바른~~" 경고 메시지는 뜨지 않죠.
제 판단으로는 write.skin.php 파일에서 자바스크립트 오류일 가능성이 매우 커보이네요.
글작성 submit할때 정상적으로 토큰이 생성되는지를 확인해 보세요.