DB 업데이트가 마지막 것만 됩니다.

DB 업데이트가 마지막 것만 됩니다.

QA

DB 업데이트가 마지막 것만 됩니다.

답변 1

본문

다중 설문조사 입력폼의 관리자 페이지를 만들고 있습니다.

입력폼은 눌러줄때마다 하나씩 생기게 하는것까지 하고,

입력폼에 수정된 데이터 값을 넣으면 디비에 업데이트를 해주는데요...

 

"$fs_id"의 마지막 꺼만 업데이트가 됩니다....

답변이 3개면 항상 마지막꺼로만 디비를 들어가네요

 

업데이트 페이지에서 $fs_id의 값을 마지막꺼만 불러오는 것 같은데요

for 문을 돌려도 안되고.. 당췌 어떻게 해야할지 모르겠습니다.

 

고수님들의 지도편달 부탁드려요 ㅠㅠ

미칠 것 같습니다.

 

 


<?php
$sub_menu = '400100';
include_once('./_common.php');
include_once(G5_EDITOR_LIB);
auth_check($auth[$sub_menu], "w");
$sql = " select * from {$g5['solution_master_table']} where fm_id = '$fm_id' ";
$fm = sql_fetch($sql);
$sql = " select * from {$g5['solution_list_table']} where fa_id = '$fa_id' ";
$fa = sql_fetch($sql);
$sql = " select * from {$g5['solution_table']} where fs_id = '$fs_id' ";
$fs = sql_fetch($sql);
$sql_common = " from {$g5['solution_table']} where fs_id";
// 테이블의 전체 레코드수만 얻음
$sql = " select count(*) as cnt " . $sql_common;
$row = sql_fetch($sql);
$total_count = $row[cnt];

$result = sql_query($sql);

$sql_common2 = " from {$g5['solution_table']} where fs_id";
// 테이블의 전체 레코드수만 얻음
$sql2 = " select count(*) as cnt " . $sql_common2;
$row2 = sql_fetch($sql2);
$sql2 = "select * $sql_common2 order by fs_id ";
$result2 = sql_query($sql2);

////////////////////////////////

$html_title = '솔루션 '.$fm['fm_subject'];
if ($w == "u")
{
    $html_title .= " 수정";
    $readonly = " readonly";
    $sql = " select * from {$g5['solution_list_table']} where fa_id = '$fa_id' ";
    $fa = sql_fetch($sql);
    if (!$fa['fa_id']) alert("등록된 자료가 없습니다.");
}
else
    $html_title .= ' 항목 입력';
$g5['title'] = $html_title.' 관리';
include_once (G5_ADMIN_PATH.'/admin.head.php');
?>
<form name="frmsolutionform" action="./solutionformupdate.php" onsubmit="return frmsolutionform_check(this);" method="post">
<input type="hidden" name="w" value="<?php echo $w; ?>">
<input type="hidden" name="fm_id" value="<?php echo $fm_id; ?>">
<input type="hidden" name="fa_id" value="<?php echo $fa_id; ?>">

<div class="tbl_frm01 tbl_wrap">
    <table>
    <caption><?php echo $g5['title']; ?></caption>
    <colgroup>
        <col class="grid_4">
        <col>
    </colgroup>
    <tbody>
    <tr>
        <th scope="row"><label for="fa_order">출력순서</label></th>
        <td colspan="3">
            <?php echo help('숫자가 작을수록 솔루션 페이지에서 먼저 출력됩니다.'); ?>
            <input type="text" name="fa_order" value="<?php echo $fa['fa_order']; ?>" id="fa_order" class="frm_input" maxlength="10" size="10">
            <?php if ($w == 'u') { ?><a href="<?php echo G5_BBS_URL; ?>/solution.php?fm_id=<?php echo $fm_id; ?>" class="btn_frmline">내용보기</a><?php } ?>
        </td>
    </tr>
    <tr>
        <th scope="row">질문</th>
        <td colspan="3"><input type="text" name="fa_subject" value="<?php echo get_text($fa['fa_subject']); ?>" style="width:99%; height:40px;" id="fa_subject" /></td>
    </tr>
  <?php
   for ($i=0; $row2=sql_fetch_array($result2); $i++)
   {
    $num = $i + 1;
  ?>
    
    <tr>
     <th scope="row">답변 <?php echo $num; ?><input type="text" name="fs_id" value="<?php echo $num; ?>" id="fs_id"></th>
        <td width="70%"><input type="text" name="fs_example" value="<?php echo get_text($row2['fs_example']); ?>" style="width:100%; height:40px;" id="fs_example" /></td>
        <td>점수: 
         <select style="width:80px; height:40px;" id="fs_point" />
                <option value="1">1점</option>
                <option value="2">2점</option>
                <option value="3">3점</option>
                <option value="4">4점</option>
                <option value="5">5점</option>
   </select></td>
        <td>이동할 질문 번호 : <input type="text" value="<?php echo get_text($row2['fs_move']); ?>" style="width:90px; height:40px;" id="fs_move" /></td>
 </tr>
    
    <?php
    }
    if ($i == 0) {
        echo '<tr><td colspan="4" class="empty_table">자료가 없습니다.</td></tr>';
    }
 
 
    ?> 
        
    
    </tbody>
    </table>
    <table id="mytable" width="100%" align="left" cellspacing="0">
    </table>
    <a href="javascript:add_row()">입력폼 추가</a> |
 <a href="javascript:delete_row()">입력폼 삭제</a>
</div>
<div class="btn_confirm01 btn_confirm">
    <input type="submit" value="확인" class="btn_submit" accesskey="s">
    <a href="./solutionlist.php?fm_id=<?php echo $fm_id; ?>">목록</a>
</div>
</form>
<script>
function frmsolutionform_check(f)
{
    errmsg = "";
    errfld = "";
    //check_field(f.fa_subject, "질문을 입력하세요.");
    //check_field(f.fa_example+index, index "답변을 입력하세요.");
    if (errmsg != "")
    {
        alert(errmsg);
        errfld.focus();
        return false;
    }
    <?php echo get_text('fa_subject'); ?>
    <?php echo get_text('fs_example'); ?>
    <?php echo get_text('fs_move'); ?>
    return true;
}
// document.getElementById('fa_order').focus(); 포커스 해제
</script>
<script>
var index    = <?php echo $total_count; ?> + 1;
var objCreateNumber  = 5;//갯수

function add_row() {
 
 if ( index > objCreateNumber ) return;
 
 mytable = document.getElementById('mytable');
 row = mytable.insertRow(mytable.rows.length);
 
 cell1 = row.insertCell(0);
 cell2 = row.insertCell(1);
 cell3 = row.insertCell(2);
 cell4 = row.insertCell(3);
 
 cell1.innerHTML = '<input type="text" name="fs_id" value="'+index+'">';
 cell2.innerHTML = '<b style="padding-right:150px;">답변 '+index+'</b><input type="text" name="fs_example" style="width:1290px; height:40px;" />';
 cell3.innerHTML = '점수 : <select name="fa_point" style="width:80px; height:40px;"><option value="1">1점</option><option value="2">2점</option><option value="3">3점</option></select>';
 cell4.innerHTML = '이동할 질문 번호 : <input type="text" name="fa_move" style="width:90px; height:40px;" />';
 
 index++;
}
function delete_row() {
 mytable = document.getElementById('mytable');
 
 if (mytable.rows.length < 1 ) return;
  mytable.deleteRow(mytable.rows.length - 1);
  
  index = index - 1;
}
</script> 

 

 

 

디비를 올려주는 페이지 소스입니다.


<?php
$sub_menu = '400200';
include_once('./_common.php');
if ($w == "u" || $w == "d")
    check_demo();
if ($W == 'd')
    auth_check($auth[$sub_menu], "d");
else
    auth_check($auth[$sub_menu], "w");
$sql_common = " fa_subject = '$fa_subject',
                fa_order = '$fa_order' ";
      
$sql_common2 = " fs_example = '$fs_example',
     fs_point = '$fs_point',
     fs_move = '$fs_move'";
 
if ($w == "")
{
    $sql = " insert {$g5['solution_list_table']}
                set fm_id ='$fm_id',
                    $sql_common ";
    sql_query($sql);
    $fa_id = mysql_insert_id();
/////////////////////////////////////////////////////// 
 $sql2 = " insert {$g5['solution_table']}
    set fs_id ='$fs_id',
     $sql_common2 ";
 sql_query($sql2);
 $fs_id = mysql_insert_id();
}
else if ($w == "u")
{
    $sql = " update {$g5['solution_list_table']}
                set $sql_common
    where fa_id = '$fa_id' ";
    sql_query($sql);

 $sql2 = " update {$g5['solution_table']}
    set $sql_common2
    where fs_id = $fs_id";
 sql_query($sql2);
 $fs_id = mysql_insert_id();
}
else if ($w == "d")
{
 $sql = " delete from {$g5['solution_list_table']} where fa_id = '$fa_id' ";
    sql_query($sql);
}
if ($w == 'd')
    goto_url("./solutionlist.php?fm_id=$fm_id");
else
    goto_url("./solutionform.php?w=u&fm_id=$fm_id&fa_id=$fa_id");
?>

이 질문에 댓글 쓰기 :

답변 1

<input type="text" name="fs_id" value="<?php echo $num; ?>" id="fs_id"> 


이부분을

<input type="text" name="fs_id[<?=$i?>]" value="<?php echo $num; ?>" id="fs_id">


이런식으로 변경하셔야 하고


입력 부분도 for 문이나 foreach 문으로 반복해서 업데이트해주셔야 합니다.


답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
filter #faq ×
전체 44
© SIRSOFT
현재 페이지 제일 처음으로