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

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

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

 

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

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

 

1888951823_1698744224.5233.jpg

 

1888951823_1698744330.8561.jpg

 

답변 6개

채택된 답변
+20 포인트

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개

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

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

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

sql_query( $sql); 

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

답변에 대한 댓글 1개

아 아뇨 없습니다.. 쿼리 실행하는게 매번있어야 하는거군요..ㅠㅠ 감사합니다

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

$g5['prize3_count'] = G5_TABLE_PREFIX.'prize3_count';

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

 

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

답변에 대한 댓글 1개

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

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

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

Copy
$wr_num = get_next_num($write_table);
위 부분을 다음과 같이 수정

 

$wr_num = get_max_num($write_table) + 1;

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

 

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

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

답변에 대한 댓글 1개

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

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

Copy
<?
include_once("./common.php");

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");
}

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

if ( empty( $_FILES[bf_file][name][0] ) ) {
    alert("잘못된 접근입니다. 이미지를 첨부해주세요.","/event_form.php");
}
?>
<title>신청완료</title>
<?
///////////////////////////////////////이미지 리사이징  https://sir.kr/g5_tip/5910
include_once("./plugin/php-image-resize-master/lib/ImageResize.php");//플러그인 경로를 확인하세요

$width= 1000; //너비 px
$height= 1000;//높이 px
$quality =90; //선명도 %

use \Gumlet\ImageResize; 

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);

}
}
/////////////////////////////////////////이미지 리사이징끝

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";


$bo_table = "dongseo";
$write_table = $g5['write_prefix'] . $bo_table;

$wr_num = get_next_num($write_table);
$wr_reply = "";

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

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";
}

//$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);

$wr_id = sql_insert_id();

//////////////////////////////////////파일첨부 bbs/write_update.php
// 디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.)
@mkdir(G5_DATA_PATH.'/file/'.$bo_table, G5_DIR_PERMISSION);
@chmod(G5_DATA_PATH.'/file/'.$bo_table, G5_DIR_PERMISSION);

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

// 가변 파일 업로드
$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'] = '';

    // 삭제에 체크가 되어있다면 파일을 삭제합니다.
    if (isset($_POST['bf_file_del'][$i]) && $_POST['bf_file_del'][$i]) {
        $upload[$i]['del_check'] = true;

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

        $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;

    $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);

    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;
        }
        //=================================================================

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

        // 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' ");

            $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']);
            }
        }

        // 프로그램 원래 파일명
        $upload[$i]['source'] = $filename;
        $upload[$i]['filesize'] = $filesize;

        // 아래의 문자열이 들어간 파일은 -x 를 붙여서 웹경로를 알더라도 실행을 하지 못하도록 함
        $filename = preg_replace("/\.(php|pht|phtm|htm|cgi|pl|exe|jsp|asp|inc)/i", "$0-x", $filename);

        shuffle($chars_array);
        $shuffle = implode('', $chars_array);

        // 첨부파일 첨부시 첨부파일명에 공백이 포함되어 있으면 일부 PC에서 보이지 않거나 다운로드 되지 않는 현상이 있습니다. (길상여의 님 090925)
        $upload[$i]['file'] = abs(ip2long($_SERVER['REMOTE_ADDR'])).'_'.substr($shuffle,0,8).'_'.replace_filename($filename);

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

        // 업로드가 안된다면 에러메세지 출력하고 죽어버립니다.
        $error_code = move_uploaded_file($tmp_file, $dest_file) or die($_FILES['bf_file']['error'][$i]);

        // 올라간 파일의 퍼미션을 변경합니다.
        chmod($dest_file, G5_FILE_PERMISSION);

        $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);
    }
}

// 나중에 테이블에 저장하는 이유는 $wr_id 값을 저장해야 하기 때문입니다.
for ($i=0; $i<count($upload); $i++)
{
    if (!get_magic_quotes_gpc()) {
        $upload[$i]['source'] = addslashes($upload[$i]['source']);
    }

    $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);

        run_event('write_update_file_insert', $bo_table, $wr_id, $upload[$i], $w);
    }
}

// 업로드된 파일 내용에서 가장 큰 번호를 얻어 거꾸로 확인해 가면서
// 파일 정보가 없다면 테이블의 내용을 삭제합니다.
$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}' ");

    // 정보가 있다면 빠집니다.
    if ($row2['bf_file']) break;

    // 그렇지 않다면 정보를 삭제합니다.
    sql_query(" delete from {$g5['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' and bf_no = '{$i}' ");
}

// 파일의 개수를 게시물에 업데이트 한다.
$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}' ");

//////////////////////////////////////파일첨부끝

// 부모 아이디에 UPDATE
sql_query(" update $write_table set wr_parent = '$wr_id' where wr_id = '$wr_id' ");

// 새글 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]' ) ");

// 게시글 1 증가
sql_query("update $g5[board_table] set bo_count_write = bo_count_write + 1 where bo_table = '$bo_table'");

$super_admin = get_admin("super");
$wr_email = $super_admin[mb_email];
mailer($wr_name, $wr_email, $super_admin[mb_email], $wr_subject, $content, 1);

?>
<script>
    document.cookie="event_join=done;"
</script>
<?

alert("이벤트 응모가 완료되었습니다.","/index.php");
?>
로그인 후 평가할 수 있습니다

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

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

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

답변에 대한 댓글 3개

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

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

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

로그인
🐛 버그신고