있으면 업데이트 없으면 인써트 채택완료
여러가지로 해보는데 안되서 선배님들의 도움을 얻고자 다시 질문드립니다,
버튼누르면 ajax 로 처리하는데요
sql문이
$sql2 = "insert into g5_test(wr_id, state, date, wr_subject, state_idx,~~~
이렇게만 되어 있어서 누를때마다 인서트됩니다, ㅎ
지금 누르는게 wr_id 3 state_idx 5 일때
등록된 자료중에 wr_id 3과 state_idx가 5로 이 두가지가 일치(동시 만족)하는 게 있으면
insert아니고 update로 처리하려면 sql문을 어떻게 해야할까요?
답변 2개
배르만 님의 답변이 원하시는 것이기는 한데요..
https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html" rel="nofollow noreferrer noopener" target="_blank">https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
이런 경우 wr_id state_idx 가 기본키로 되어있어야 합니다.
그런 설정이 아닐 것 같은데요..
이런 경우 아래처럼 코딩하세요.
if ($wr_id==3 && state_idx==5){
update
}else{
insert
}
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
링크가 도움이 될지 모르겠습니다.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
맞습니다, 기본키는 아닙니다,
if ($wr_id==3 && state_idx==5){
에서 wr_id 3 idx 5는 다른 버튼 누를때, 또 다른 페이지에서 바뀌는데,,,
if ($wr_id== $wr_id && state_idx==$state_idx){
가 될련지 모르겠습니다, ㅎ