DB 테이블에 데이터를 버튼으로 삭제하기
본문
g4_gawibawibo 라는 테이블이 있고
인풋값에 mb_id 를 기입후 삭제버튼 클릭하면 해당 g4_gawibawibo 테이블에 해당하는 mb_id필드에 입력값이 삭제되도록 할수 있나요? ㅎ
<input type="text"><a href="#">삭제</a>
답변 3
# html 부분
<form action="./gawibawibo_delete.php" onsubmit="check(this)">
<input type="text" name="mb_id">
<input type="submit" value="삭제">
</form>
<script type="text/javascript">
function check(f) {
if (!f.mb_id.value) {
alert('아이디를 입력해 주세요.');
f.mb_id.focus();
}
if (!confirm('입력한' + f.mb_id.value + ' 아이디를 정말 삭제하시겠습니까?'))
return false;
}
</script>
# update 부분
include_once('./common.php');
// 입력한 아이디가 있는지 조회한다.
$result = sql_fetch("select mb_id from g4_gawibawibo where mb_id = {$mb_id}");
if ($result['mb_id'])
sql_query("delete from g4_gawibawibo where mb_id = {$mb_id}");
else
alert("입력한 {$mb_id} 아이디는 존재하지 않습니다.");
!-->!-->
...
삭제화면
<form action="del.php" method="post">
<input type="text" name="mb_id" size="30">
<input type="submit" name="submit" value="삭제">
</form>
del.php
...
$query = "delete from g4_gawibawibo where mb_id='$mb_id' ";
$result = mysql_query($query, mysql_connect("localhost","아이디","비밀번호") or die (mysql_error()));
...
<script type="text/javascript">
location.href="이동할 url";
</script>
=========================================================================
꿀꿀*코구녕님과 같은, 그누고수님들께는 班门弄斧 (반문농부) 격의 답변이 되겠군요.
허접한 프로그램입니다만, 작게나마 도움이 될수 있었으면 하는 바램입니다. ㅎㅎ
감사합니다 다들 도움 되었습니다 ^^ 알려주신것과 도움주신것과 오류등을 해석하여 수정합니다.
<?php if ($is_admin) {?>
<form action="./gawibawibo_delete.php" onsubmit="return check(this)">
<input type="text" name="mb_id">
<input type="submit" value="삭제">
</form>
<script type="text/javascript">
function check(f) {
if (!f.mb_id.value) {
alert('아이디를 입력해 주세요.');
f.mb_id.focus();
return false;
}
if (!confirm('입력한' + f.mb_id.value + ' 아이디를 정말 삭제하시겠습니까?'))
return false;
}
</script>
<? } ?>
# update 부분
<?
include_once('./_common.php');
// 입력한 아이디가 있는지 조회한다.
$result = sql_fetch("select mb_id from g4_gawibawibo where mb_id = '$mb_id'");
if ($result['mb_id'])
sql_query("delete from g4_gawibawibo where mb_id = '$mb_id'");
else
alert("입력한 {$mb_id} 아이디는 존재하지 않습니다.");
?>
!-->!-->