테스트 사이트 - 개발 중인 베타 버전입니다

db테이블 1증가 시키기 채택완료

코딩초보 2년 전 조회 3,587

안녕하세요! db 테이블을 생성해서 글쓰면 
1씩 증가하게 하려고하는데 

틀린게 없는것 같은데 증가가 안되네요...ㅠㅠ 뭐가 문제일까요? 

 

$sql = "update {$g5['prize3_count']} set pc_num=pc_num+1 where pc_id = 1";

이코드인데 이코드 밑으로 다른 코드들은 정상작동해서 글작성도 다 잘됩니다

 

 

 

댓글을 작성하려면 로그인이 필요합니다.

답변 6개

채택된 답변
+20 포인트
2년 전

if ($wr_5 == 1) {
  $sql = "update g5_prize1_count set pc_num = pc_num + 1 where pc_id = 1";
} else if ($wr_5 == 2) {
  $sql = "update g5_prize2_count set pc_num = pc_num + 1 where pc_id = 1";
} else if ($wr_5 == 3) {
  $sql = "update g5_prize3_count set pc_num = pc_num + 1 where pc_id = 1";
}

sql_query($sql);

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

코딩초보
2년 전
if문은 원래 이렇게 했는데 안되길래 저렇게 해본거거든요..ㅠ sql_query가 있어야 하는군요.. 감사합니다

댓글을 작성하려면 로그인이 필요합니다.

2년 전

질문코드 다음에 다음 코드가 있나요?

sql_query( $sql); 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

코딩초보
2년 전
아 아뇨 없습니다.. 쿼리 실행하는게 매번있어야 하는거군요..ㅠㅠ 감사합니다

댓글을 작성하려면 로그인이 필요합니다.

ifelse
2년 전
$g5['prize3_count'] = G5_TABLE_PREFIX.'prize3_count';

이거 선언 하신건가요?? 테이블값이 왠지 빈값일거 같다는 느낌적 느낌...

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

코딩초보
2년 전
제가 다 이해하고 하는게 아니라서 잘 모르겠습니다 ㅠㅠ db테이블에 생성해두긴했어요

댓글을 작성하려면 로그인이 필요합니다.

다음과 같은 방법으로 해결 될 수 있지 않을까 합니다.

</p>

<p>$wr_num = get_next_num($write_table);

위 부분을 다음과 같이 수정</p>

<p> </p>

<p>$wr_num = get_max_num($write_table) + 1;

wr_num의 글번호에 1을 더한 값이 할당됩니다. 그러나 이 방법은 동시에 글을 작성하는 경우 중복된 번호를 생성할 수 있고, 데이터베이스 무결성 문제를 야기할 수 있으므로 권장하지 않습니다.

 

글 번호를 증가시키는 대신 데이터베이스의 자동 증가 기능을 활용하거나 다른 고유한 식별자를 사용하는 것이 더 좋은 방법이 되지 않을까 생각합니다.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

코딩초보
2년 전
그러네요.. 동시에 작성된경우.. 참고해서 수정 해보겠습니다 감사합니다..

댓글을 작성하려면 로그인이 필요합니다.

코딩초보

</p>

<p><?

include_once("./common.php");</p>

<p>if ( empty( $wr_name ) ) {

    alert("잘못된 접근입니다. 성함을 적어주세요.","/event_form.php");//2020-10-14 index.php -> event_form.php

}

if ( empty( $wr_2 ) ) {

    alert("잘못된 접근입니다. 휴대폰번호를 적어주세요.","/event_form.php");

}

if ( empty( $wr_3 ) ) {

    alert("잘못된 접근입니다. 주소를 적어주세요.","/event_form.php");

}</p>

<p>if ( empty( $wr_4 ) ) {

    alert("잘못된 접근입니다. 구매처를 선택해주세요.","/event_form.php");

}</p>

<p>if ( empty( $_FILES[bf_file][name][0] ) ) {

    alert("잘못된 접근입니다. 이미지를 첨부해주세요.","/event_form.php");

}

?>

<title>신청완료</title>

<?

///////////////////////////////////////이미지 리사이징  <a href="https://sir.kr/g5_tip/5910" target="_blank" rel="noopener noreferrer">https://sir.kr/g5_tip/5910</a>

include_once("./plugin/php-image-resize-master/lib/ImageResize.php");//플러그인 경로를 확인하세요</p>

<p>$width= 1000; //너비 px

$height= 1000;//높이 px

$quality =90; //선명도 %</p>

<p>use \Gumlet\ImageResize; </p>

<p>for ($i=0; $i<count($_FILES['bf_file']['name']); $i++) {

    //이미지 내용 확인

  $tmp_file  = $_FILES['bf_file']['tmp_name'][$i];

    $filename  = $_FILES['bf_file']['name'][$i];

   

//이미지 확장자 검사

if($filename && preg_match("/\.({$config['cf_image_extension']})$/i", $filename)){

// image type 검사

$timg = @getimagesize($tmp_file);

if ($timg['2'] < 1 || $timg['2'] > 16){

continue;

}

//이미지 변경

$image = new ImageResize($tmp_file);

$image->resizeToBestFit($width, $height);

$image->save($tmp_file, null, $quality);

                $_FILES['bf_file']['size'][$i]=filesize($tmp_file);

unset($image);</p>

<p>}

}

/////////////////////////////////////////이미지 리사이징끝</p>

<p>include_once("./lib/mailer.lib.php");

ob_start();

include_once ("./bbs/write_update_mail.php");

$content = ob_get_contents();

ob_end_clean();

$wr_1 = "$hp1-$hp2-$hp3";</p>

<p>

$bo_table = "dongseo";

$write_table = $g5['write_prefix'] . $bo_table;</p>

<p>$wr_num = get_next_num($write_table);

$wr_reply = "";</p>

<p>$wr_subject = "{$_POST[wr_name]}님의 응모 정보입니다.";</p>

<p>session_start(); // 세션 시작

$wr_5 = $_SESSION['prize']; // 세션에서 값을 가져와서 $wr_5에 대입

if ($wr_5 == 1) {

    $sql = "update {$g5['prize1_count']} set pc_num=pc_num+1 where pc_id = 1";

} elseif ($wr_5 == 2) {

    $sql = "update {$g5['prize2_count']} set pc_num=pc_num+1 where pc_id = 1";

} elseif ($wr_5 == 3) {

    $sql = "update {$g5['prize3_count']} set pc_num=pc_num+1 where pc_id = 1";

}</p>

<p>//$secret = "secret";

    //wr_name hp1 style price coupon

    $sql = " insert into $write_table

                set wr_num = '$wr_num',

                     wr_reply = '$wr_reply',

                     wr_comment = 0,

                     ca_name = '$ca_name',

                     wr_option = '$html,$secret,$mail',

                     wr_subject = '$wr_subject',

                     wr_content = '$wr_content',

                     wr_link1 = '$wr_link1',

                     wr_link2 = '$wr_link2',

                     wr_link1_hit = 0,

                     wr_link2_hit = 0,

                     wr_hit = 0,

                     wr_good = 0,

                     wr_nogood = 0,

                     mb_id = '{$member['mb_id']}',

                     wr_password = '$wr_password',

                     wr_name = '$wr_name',

                     wr_email = '$wr_email',

                     wr_homepage = '$wr_homepage',

                     wr_datetime = '".G5_TIME_YMDHIS."',

                     wr_last = '".G5_TIME_YMDHIS."',

                     wr_ip = '{$_SERVER['REMOTE_ADDR']}',

                     wr_1 = '$wr_1',

                     wr_2 = '$wr_2',

                     wr_3 = '$wr_3',

                     wr_4 = '$wr_4',

                     wr_5 = '$wr_5',

                     wr_6 = '$wr_6',

                     wr_7 = '$wr_7',

                     wr_8 = '$wr_8',

                     wr_9 = '$wr_9',

                     wr_10 = '$wr_10' ";

    sql_query($sql);</p>

<p>$wr_id = sql_insert_id();</p>

<p>//////////////////////////////////////파일첨부 bbs/write_update.php

// 디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.)

@mkdir(G5_DATA_PATH.'/file/'.$bo_table, G5_DIR_PERMISSION);

@chmod(G5_DATA_PATH.'/file/'.$bo_table, G5_DIR_PERMISSION);</p>

<p>$chars_array = array_merge(range(0,9), range('a','z'), range('A','Z'));</p>

<p>// 가변 파일 업로드

$file_upload_msg = '';

$upload = array();

for ($i=0; $i<count($_FILES['bf_file']['name']); $i++) {

    $upload[$i]['file']     = '';

    $upload[$i]['source']   = '';

    $upload[$i]['filesize'] = 0;

    $upload[$i]['image']    = array();

    $upload[$i]['image'][0] = '';

    $upload[$i]['image'][1] = '';

    $upload[$i]['image'][2] = '';

    $upload[$i]['fileurl'] = '';

    $upload[$i]['thumburl'] = '';

    $upload[$i]['storage'] = '';</p>

<p>    // 삭제에 체크가 되어있다면 파일을 삭제합니다.

    if (isset($_POST['bf_file_del'][$i]) && $_POST['bf_file_del'][$i]) {

        $upload[$i]['del_check'] = true;</p>

<p>        $row = sql_fetch(" select * from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");</p>

<p>        $delete_file = run_replace('delete_file_path', G5_DATA_PATH.'/file/'.$bo_table.'/'.str_replace('../', '', $row['bf_file']), $row);

        if( file_exists($delete_file) ){

            @unlink($delete_file);

        }

        // 썸네일삭제

        if(preg_match("/\.({$config['cf_image_extension']})$/i", $row['bf_file'])) {

            delete_board_thumbnail($bo_table, $row['bf_file']);

        }

    }

    else

        $upload[$i]['del_check'] = false;</p>

<p>    $tmp_file  = $_FILES['bf_file']['tmp_name'][$i];

    $filesize  = $_FILES['bf_file']['size'][$i];

    $filename  = $_FILES['bf_file']['name'][$i];

    $filename  = get_safe_filename($filename);</p>

<p>    if (is_uploaded_file($tmp_file)) {

        

        //=================================================================\

        // 090714

        // 이미지나 플래시 파일에 악성코드를 심어 업로드 하는 경우를 방지

        // 에러메세지는 출력하지 않는다.

        //-----------------------------------------------------------------

        $timg = @getimagesize($tmp_file);

        // image type

        if ( preg_match("/\.({$config['cf_image_extension']})$/i", $filename) ||

             preg_match("/\.({$config['cf_flash_extension']})$/i", $filename) ) {

            if ($timg['2'] < 1 || $timg['2'] > 16)

                continue;

        }

        //=================================================================</p>

<p>        $upload[$i]['image'] = $timg;</p>

<p>        // 4.00.11 - 글답변에서 파일 업로드시 원글의 파일이 삭제되는 오류를 수정

        if ($w == 'u') {

            // 존재하는 파일이 있다면 삭제합니다.

            $row = sql_fetch(" select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '$i' ");</p>

<p>            $delete_file = run_replace('delete_file_path', G5_DATA_PATH.'/file/'.$bo_table.'/'.str_replace('../', '', $row['bf_file']), $row);

            if( file_exists($delete_file) ){

                @unlink(G5_DATA_PATH.'/file/'.$bo_table.'/'.$row['bf_file']);

            }

            // 이미지파일이면 썸네일삭제

            if(preg_match("/\.({$config['cf_image_extension']})$/i", $row['bf_file'])) {

                delete_board_thumbnail($bo_table, $row['bf_file']);

            }

        }</p>

<p>        // 프로그램 원래 파일명

        $upload[$i]['source'] = $filename;

        $upload[$i]['filesize'] = $filesize;</p>

<p>        // 아래의 문자열이 들어간 파일은 -x 를 붙여서 웹경로를 알더라도 실행을 하지 못하도록 함

        $filename = preg_replace("/\.(php|pht|phtm|htm|cgi|pl|exe|jsp|asp|inc)/i", "$0-x", $filename);</p>

<p>        shuffle($chars_array);

        $shuffle = implode('', $chars_array);</p>

<p>        // 첨부파일 첨부시 첨부파일명에 공백이 포함되어 있으면 일부 PC에서 보이지 않거나 다운로드 되지 않는 현상이 있습니다. (길상여의 님 090925)

        $upload[$i]['file'] = abs(ip2long($_SERVER['REMOTE_ADDR'])).'_'.substr($shuffle,0,8).'_'.replace_filename($filename);</p>

<p>        $dest_file = G5_DATA_PATH.'/file/'.$bo_table.'/'.$upload[$i]['file'];</p>

<p>        // 업로드가 안된다면 에러메세지 출력하고 죽어버립니다.

        $error_code = move_uploaded_file($tmp_file, $dest_file) or die($_FILES['bf_file']['error'][$i]);</p>

<p>        // 올라간 파일의 퍼미션을 변경합니다.

        chmod($dest_file, G5_FILE_PERMISSION);</p>

<p>        $dest_file = run_replace('write_update_upload_file', $dest_file, $board, $wr_id, $w);

        $upload[$i] = run_replace('write_update_upload_array', $upload[$i], $dest_file, $board, $wr_id, $w);

    }

}</p>

<p>// 나중에 테이블에 저장하는 이유는 $wr_id 값을 저장해야 하기 때문입니다.

for ($i=0; $i<count($upload); $i++)

{

    if (!get_magic_quotes_gpc()) {

        $upload[$i]['source'] = addslashes($upload[$i]['source']);

    }</p>

<p>    $row = sql_fetch(" select count(*) as cnt from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");

    if ($row['cnt'])

    {

        // 삭제에 체크가 있거나 파일이 있다면 업데이트를 합니다.

        // 그렇지 않다면 내용만 업데이트 합니다.

        if ($upload[$i]['del_check'] || $upload[$i]['file'])

        {

            $sql = " update {$g5['board_file_table']}

                        set bf_source = '{$upload[$i]['source']}',

                             bf_file = '{$upload[$i]['file']}',

                             bf_content = '{$bf_content[$i]}',

                             bf_fileurl = '{$upload[$i]['fileurl']}',

                             bf_thumburl = '{$upload[$i]['thumburl']}',

                             bf_storage = '{$upload[$i]['storage']}',

                             bf_filesize = '{$upload[$i]['filesize']}',

                             bf_width = '{$upload[$i]['image']['0']}',

                             bf_height = '{$upload[$i]['image']['1']}',

                             bf_type = '{$upload[$i]['image']['2']}',

                             bf_datetime = '".G5_TIME_YMDHIS."'

                      where bo_table = '{$bo_table}'

                                and wr_id = '{$wr_id}'

                                and bf_no = '{$i}' ";

            sql_query($sql);

        }

        else

        {

            $sql = " update {$g5['board_file_table']}

                        set bf_content = '{$bf_content[$i]}'

                        where bo_table = '{$bo_table}'

                                  and wr_id = '{$wr_id}'

                                  and bf_no = '{$i}' ";

            sql_query($sql);

        }

    }

    else

    {

        $sql = " insert into {$g5['board_file_table']}

                    set bo_table = '{$bo_table}',

                         wr_id = '{$wr_id}',

                         bf_no = '{$i}',

                         bf_source = '{$upload[$i]['source']}',

                         bf_file = '{$upload[$i]['file']}',

                         bf_content = '{$bf_content[$i]}',

                         bf_fileurl = '{$upload[$i]['fileurl']}',

                         bf_thumburl = '{$upload[$i]['thumburl']}',

                         bf_storage = '{$upload[$i]['storage']}',

                         bf_download = 0,

                         bf_filesize = '{$upload[$i]['filesize']}',

                         bf_width = '{$upload[$i]['image']['0']}',

                         bf_height = '{$upload[$i]['image']['1']}',

                         bf_type = '{$upload[$i]['image']['2']}',

                         bf_datetime = '".G5_TIME_YMDHIS."' ";

        sql_query($sql);</p>

<p>        run_event('write_update_file_insert', $bo_table, $wr_id, $upload[$i], $w);

    }

}</p>

<p>// 업로드된 파일 내용에서 가장 큰 번호를 얻어 거꾸로 확인해 가면서

// 파일 정보가 없다면 테이블의 내용을 삭제합니다.

$row = sql_fetch(" select max(bf_no) as max_bf_no from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' ");

for ($i=(int)$row['max_bf_no']; $i>=0; $i--)

{

    $row2 = sql_fetch(" select bf_file from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");</p>

<p>    // 정보가 있다면 빠집니다.

    if ($row2['bf_file']) break;</p>

<p>    // 그렇지 않다면 정보를 삭제합니다.

    sql_query(" delete from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");

}</p>

<p>// 파일의 개수를 게시물에 업데이트 한다.

$row = sql_fetch(" select count(*) as cnt from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' ");

sql_query(" update {$write_table} set wr_file = '{$row['cnt']}' where wr_id = '{$wr_id}' ");</p>

<p>//////////////////////////////////////파일첨부끝</p>

<p>// 부모 아이디에 UPDATE

sql_query(" update $write_table set wr_parent = '$wr_id' where wr_id = '$wr_id' ");</p>

<p>// 새글 INSERT

sql_query(" insert into $g5[board_new_table] ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '$bo_table', '$wr_id', '$wr_id', '$g4[time_ymdhis]', '$member[mb_id]' ) ");</p>

<p>// 게시글 1 증가

sql_query("update $g5[board_table] set bo_count_write = bo_count_write + 1 where bo_table = '$bo_table'");</p>

<p>$super_admin = get_admin("super");

$wr_email = $super_admin[mb_email];

mailer($wr_name, $wr_email, $super_admin[mb_email], $wr_subject, $content, 1);</p>

<p>?>

<script>

    document.cookie="event_join=done;"

</script>

<?</p>

<p>alert("이벤트 응모가 완료되었습니다.","/index.php");

?></p>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

toqurk
2년 전

DB 구조를 보여주실 필요없고 증가시키는 쿼리문을 보여주세요.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 3개

코딩초보
2년 전
저 코드가 쿼리문아닌가요?;;
코딩초보
2년 전
댓글에 올린게 풀코드입니다..ㅠ 뭐를 말씀하시는지 잘 모르겠어요
t
toqurk
2년 전
헙!!! 제가 보고 답변 달때는 저 영역이 없었는데..갑자기 생겼네요..

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인