티스토리 뷰
데이터 삭제
이름으로 검색한뒤 해당 레코드셋을 delete 쿼리로 전체 열을 삭제한다.
소스
<!DOCTYPE HTML>
<html lang="ko">
<head>
<title> 학생삭제 </title>
<meta charset="utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<center>
<!-- 검색모드 -->
<h3>학생검색 후 삭제</h3>
<form name="데이터수정" method="POST" action="<?php echo $PHP_SELF; ?>">
이름 : <input type=text name="name" value="<?php echo $_POST['name']; ?>"><br />
<input type="hidden" name="mode" value='search'><br />
<input type="submit" value="검색" />
<input type="reset" value="취소" />
</form>
<hr /><br />
<?php
$name = $_POST['name'];
if($name){
$connect = mysql_connect('localhost', 'admin', '1234');
mysql_select_db('student_db', $connect);
$mode = $_POST['mode'];
if( $mode == 'delete' ){
$hakbeon = $_POST['hakbeon'];
$hakgwa = $_POST['hakgwa'];
$tel = $_POST['tel'];
$sql = "delete from list_table ";
$sql .= "where hakbeon='$hakbeon'";
@mysql_query("set names utf8");
$result = mysql_query($sql, $connect);
}
$sql = "select * from list_table where name = '$name'";
@mysql_query("set names utf8");
$result = mysql_query($sql, $connect);
$row = mysql_fetch_assoc($result);
echo "<h3>삭제하기</h3>";
echo "<form name='삭제하기' method='POST' action='$PHP_SELF'>";
echo "학번 : <input type='text' name='hakbeon' readonly value='$row[hakbeon]' /><br />";
echo "이름 : <input type='text' name='name' readonly value='$row[name]' /><br />";
echo "학과 : <input type='text' name='hakgwa' readonly value='$row[hakgwa]' /><br />";
echo "전화 : <input type='text' name='tel' readonly value='$row[tel]' /><br />";
echo "<input type='hidden' name='mode' value='delete' />";
echo "<input type='submit' value='삭제'>";
echo "<input type='reset' value='취소'>";
echo "<a href='http://localhost/student/02.php'><input type='button' value='리스트 보기'></a>";
echo "</form>";
mysql_free_result($result);
mysql_close($connect);
}
?>
</center>
</body>
</html>
'■ 백엔드 ■ > PHP' 카테고리의 다른 글
| PHPExcel ? (0) | 2014.04.07 |
|---|---|
| session을 이용한 로그인 페이지 통신 기초 (0) | 2014.02.14 |
| 9. 학생 명단 수정 (0) | 2014.02.14 |
| 8. 학생 데이터 추가 (0) | 2014.02.14 |
| 7. 학생 명단 검색 (0) | 2014.02.14 |
댓글