15. Mysql을 이용한 메모장 (6) 삭제 -php-

 

 

-memo_delete.php

 

조건문이 거짓인 경우

boolean FALSE, 숫자 int 0, float 0.0, 빈 문자, 문자 "0", 아무 구성요소도 갖지 않는 배열, 아무 멤버 변수도 갖지 않는 객체, 특별한 타입인 NULL (변수를 unset하는 것도 포함)

이 외에는 참.

 

memo_delete.php

<?

include "memo.php";

if(!$_GET['m_idx']){ // m_idx값이 넘어왔는지 검사.

?>

<script>

alert("메모의 고유번호가 없음.");

history.back();

</script>

<?

exit;

} else {

$db_host = "mysql.com";

$db_user = "mydb";

$db_pass = "password";

$db_name = "db이름";

//database와 연결.

$connect=mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());

mysql_query("set names utf8");//한글 입력을 위한 설정.

mysql_select_db($db_name) or die(mysql_error());

 

//데이터 읽기

$query="SELECT * FROM sample_memo WHERE m_idx='$m_idx'";

$result=mysql_query($query);

$data=mysql_fetch_array($result);//한 행만 불러오면 되므로 그냥 한 번만 대입해서 사용.

if(!$data['m_idx']){ //해당 글이 없는 경우

?>

<script>

alert("메모가 없음");

history.back();

</script>

<?

exit;

} // if문 닫기

?>

<!--삭제용 form 작성 -->

<br>

<form name="iform" method="post" action="memo_delete_update.php">

<input type="hidden" name="m_idx" value="<?=$data['m_idx']?>">

<table style="width:500px; height:50px; border:5px #cccccc solid;">

<tr>

<td align="center" valign="middle">

메모 삭제 하기

</td>

</tr>

</table>

<table style="width:500px; height:50px; border:5px #cccccc solid;">

<tr>

<td align="center" valign="middle">비밀번호</td>

<td align="center" valign="middle">

<input type="password" name="m_pass" style="width:380px;">

</td>

</tr>

<tr>

<td colspan=2 align="center" valign="middle">

<input type="submit" value="삭제">

</td>

</tr>

</table>

</form>

<?

mysql_close($connect);

?>

Posted by star story :

Snippet :: Code View :: "+location.href+'
'+b+"

");top.consoleRef.document.close()}$(".snippet-container").each(function(b){$(this).find("a.snippet-text").click(function(){var d=$(this).parents(".snippet-wrap").find(".snippet-formatted");var c=$(this).parents(".snippet-wrap").find(".snippet-textonly");d.toggle();c.toggle();if(c.is(":visible")){$(this).html("html")}else{$(this).html("text")}return false});$(this).find("a.snippet-window").click(function(){var c=$(this).parents(".snippet-wrap").find(".snippet-textonly").html();a(c);$(this).blur();return false})});$(".snippet-toggle").each(function(b){$(this).click(function(){$(this).parents(".snippet-container").find(".snippet-wrap").toggle()})})});