ajax 질문좀 드릴게요
본문
어제까지는 insert가 잘 되다가 오늘 갑자기 안되네요
<?php
include_once("../../../common.php");
if($_POST)
$tid = $_POST["tid"];
$trdate = $_POST["trdate"];
$trserial = $_POST["trserial"];
$trdt = $_POST["trdt"];
$accIn = $_POST["accIn"];
$accOut = $_POST["accOut"];
$balance = $_POST["balance"];
$remark1 = $_POST["remark1"];
$remark2 = $_POST["remark2"];
$remark3 = $_POST["remark3"];
$remark4 = $_POST["remark4"];
$regDT = $_POST["regDT"];
$memo = $_POST["memo"];
$sql = "insert into {$g5['search_table']}
set tid = '$tid',
trdate = '$trdate',
trserial = '$trserial',
trdt = '$trdt',
accIn = '$accIn',
accOut = '$accOut',
balance = '$balance',
remark1 = '$remark1',
remark2 = '$remark12',
remark3 = '$remark3',
remark4 = '$remark4',
regDT = '$regDT',
memo = '$memo',
mb_id = '{$member['mb_id']}' where tid <> '{$tid}";
sql_query($sql);
?>
<body>
<div id='content'>
<p class='heading1'>Response<?php echo $_GET["JobID"]; ?><?php echo $_GET["UserID"]; ?></p>
<br/>
<fieldset class='fieldset1'>
<legend>수집 결과 조회</legend>
<ul>
<?php
if ( isset($code) ) {
?>
<li>Response.code : <?php echo $code ?> </li>
<li>Response.message : <?php echo $message ?></li>
<?php
} else {
?>
<li>code (응답코드) : <?php echo $response->code ?></li>
<li>message (응답메시지) : <?php echo $response->message ?></li>
<li>total (총 검색결과 건수) : <?php echo $response->total ?></li>
<li>perPage (페이지당 검색개수) : <?php echo $response->perPage ?></li>
<li>pageNum (페이지 번호) : <?php echo $response->pageNum ?></li>
<li>pageCount (페이지 개수) : <?php echo $response->pageCount ?></li>
<li>lastScrapDT (최종 조회일시) : <?php echo $response->lastScrapDT ?></li>
<?php
for ( $i = 0; $i < Count ( $response->list ); $i++ ) {
?>
<fieldset class='fieldset2'>
<legend> 거래내역 </legend>
<ul>
<li>tid (거래내역 아이디) : <?php echo $response->list[$i]->tid ; ?></li>
<li>trdate (거래일자) : <?php echo $response->list[$i]->trdate ; ?></li>
<li>trserial (거래일련번호) : <?php echo $response->list[$i]->trserial ; ?></li>
<li>trdt (거래일시) : <?php echo $response->list[$i]->trdt ; ?></li>
<li>accIn (입금액) : <?php echo $response->list[$i]->accIn ; ?></li>
<li>accOut (출금액) : <?php echo $response->list[$i]->accOut ; ?></li>
<li>balance (잔액) : <?php echo $response->list[$i]->balance ; ?></li>
<li>remark1 (비고 1) : <?php echo $response->list[$i]->remark1 ; ?></li>
<li>remark2 (비고 2) : <?php echo $response->list[$i]->remark2 ; ?></li>
<li>remark3 (비고 3) : <?php echo $response->list[$i]->remark3 ; ?></li>
<li>remark4 (비고 4) : <?php echo $response->list[$i]->remark4 ; ?></li>
<li>regDT (등록일시) : <?php echo $response->list[$i]->regDT ; ?></li>
<li>memo (메모) : <?php echo $response->list[$i]->memo ; ?></li>
</ul>
</fieldset>
<?php
}
}
?>
</ul>
</fieldset>
</div>
</body>
<script>
<?php
for ( $i = 0; $i < Count ( $response->list ); $i++ ) {
?>
$.ajax({
url:"http://uksoft.iwinv.net/theme/gram/mobile/api.php",
method:"POST",
data: {mb_id:'<?php echo $mb_id ?>',tid:'<?php echo $response->list[$i]->tid ; ?>',trdate:'<?php echo $response->list[$i]->trdate ; ?>',trserial:'<?php echo $response->list[$i]->trserial ; ?>',trdt:'<?php echo $response->list[$i]->trdt ; ?>',accIn:'<?php echo $response->list[$i]->accIn ; ?>',accOut:'<?php echo $response->list[$i]->accOut ; ?>',balance:'<?php echo $response->list[$i]->balance ; ?>',remark1:'<?php echo $response->list[$i]->remark1 ; ?>',remark2:'<?php echo $response->list[$i]->remark2 ; ?>',remark3:'<?php echo $response->list[$i]->remark3 ; ?>',remark4:'<?php echo $response->list[$i]->remark4 ; ?>',regDT:'<?php echo $response->list[$i]->regDT ; ?>',memo:'<?php echo $response->list[$i]->memo ; ?>'}
});
<?php } ?>
</script>
코드입니다
새벽까지만 해도 insert 가 잘 되었는데 갑자기 안되네요 ㅠㅠ
!-->!-->답변 4
mb_id = '{$member['mb_id']}' where tid <> '{$tid}";
=>
mb_id = '{$member['mb_id']}' ";
잘되던게 안되면 insert 쿼리문을 출력해서 살펴보세요.
$sql = "insert into {$g5['search_table']}
set tid = '$tid',
trdate = '$trdate',
trserial = '$trserial',
trdt = '$trdt',
accIn = '$accIn',
accOut = '$accOut',
balance = '$balance',
remark1 = '$remark1',
remark2 = '$remark12',
remark3 = '$remark3',
remark4 = '$remark4',
regDT = '$regDT',
memo = '$memo',
mb_id = '{$member['mb_id']}' where tid <> '{$tid}";
sql_query($sql);
echo $sql;
exit;
for ( $i = 0; $i < Count ( $response->list ); $i++ ) {
이부분을
for ( $i = 0; $i < count ( $response->list ); $i++ ) {
으로바꿔보세요
대문자로되어있네요.
이전 질문에도 말씀드렸듯이
13.2.6.2 INSERT ... ON DUPLICATE KEY UPDATE Statement
https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html
If you specify an ON DUPLICATE KEY UPDATE
clause and a row to be inserted would cause a duplicate value in a UNIQUE
index or PRIMARY KEY
, an UPDATE
of the old row occurs.
tid를UNIQUE
index orPRIMARY KEY로 만드시고
$sql = "insert into {$g5['search_table']} set tid = '$tid', trdate = '$trdate', trserial = '$trserial', trdt = '$trdt', accIn = '$accIn', accOut = '$accOut', balance = '$balance', remark1 = '$remark1', remark2 = '$remark12', remark3 = '$remark3', remark4 = '$remark4', regDT = '$regDT', memo = '$memo', mb_id = '{$member['mb_id']}'
ON DUPLICATE KEY UPDATE trdatec='$trdate'";
이렇게 해 보세요.
tid가 기존이 있으면
trdate만 업데이트됩니다.