insert와 update를 한 php내에서 사용한다.
zcompany.edit.php = INSERT, UPDATE 화면
zcompany_update.php = INSERT, UPDATE 처리
이 둘을 구분하기 위해서 신규등록일 때 주소를 ?mode=new로 고정시킨다.
만약 mode가 new 이면 신규등록모드이고,
mode가 new가 아니면 수정모드가 된다.
(mode가 new이면 $sql문을 쓸 필요도 없기 때문에 이 모든 걸 if문에 넣어서 update할 때만 쓸 수 있게 걸러내야 한다.)
if ($mode != "new"){ // 수정모드일때
if((int)$cid==0) alert("잘못된 접근입니다.", $href_list);
//if($cid==null || $cid=="" || $cid==0){
// alert("잘못된 접근입니다.", $href_list);
//}
$sql = "select * from zcompany where id=$cid";
$row = sql_fetch($sql);
// echo $sql.'<br>';
// print_r2 ($row);
if($row==null) alert("자료가 존재하지 않습니다", $href_list);
}
번외) 같은 페이지를 쓰기 때문에 사용자에게 보여지는 title이름도 경우에 따라 바꿔줘야한다.
$mode_title = ($mode=="new") ? "신규등록" : "거래처 상세보기 수정";
전체코드는
<?php
include_once('./_common.php');
define('_WORK_', true);
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_PATH.'/head.php');
add_stylesheet('<link rel="stylesheet" href="zcompany.css">', 0);
$href_list = G5_URL."/work/zcompany.list.php";
$href_update = G5_URL."/work/zcompany_update.php";
// if ($cid == null) echo "null입니다";
// if ($cid == "") echo "empty입니다";
// if ($cid == "0") echo "String zero 입니다";
// if ($cid == 0) echo "숫자 0 입니다";
if ($mode != "new"){ // 수정모드일때
if((int)$cid==0) alert("잘못된 접근입니다.", $href_list);
$sql = "select * from zcompany where id=$cid";
$row = sql_fetch($sql);
// echo $sql.'<br>';
// print_r2 ($row);
if($row==null) alert("자료가 존재하지 않습니다", $href_list);
}
$mode_title = ($mode=="new") ? "신규등록" : "거래처 상세보기 수정";
?>
<form name="frm_edit" id="frm_edit" action="<?php echo $href_update ?>" method="post">
<input type="hidden" name="cid" value="<?php echo $cid?>">
<input type="hidden" name="mode" value="<?php echo $mode?>">
<div class="zcom_view01">
<p><?php echo $mode_title ?></p>
<div class="view01_btn"><button type="submit">자료저장</button></div>
<table>
<tbody>
<tr>
<th>거래처명</th>
<td><input type="text" name="cname" value="<?php echo $row['cname'] ?>"></td>
<th>대표자</th>
<td><input type="text" name="ceo" value="<?php echo $row['ceo'] ?>"></td>
</tr>
<tr>
<th>주소</th>
<td colspan=3><input type="text" name="address" value="<?php echo $row['address'] ?>"></td>
</tr>
<tr>
<th>전화번호</th>
<td><input type="text" name="tel" value="<?php echo $row['tel'] ?>"></td>
<th>핸드폰번호</th>
<td><input type="text" name="hp" value="<?php echo $row['hp'] ?>"></td>
</tr>
<tr>
<th>사업시작일</th>
<td><input type="text" name="dtstart" value="<?php echo $row['dtstart'] ?>"></td>
<th>사업자번호</th>
<td><input type="text" name="cnumber" value="<?php echo $row['cnumber'] ?>"></td>
</tr>
<tr>
<th>기초잔액</th>
<td><input type="text" name="smoney" value="<?php echo $row['smoney'] ?>"></td>
<th>거래잔액</th>
<td><input type="text" name="tmoney" value="<?php echo $row['tmoney'] ?>"></td>
</tr>
</tbody>
</table>
</div>
</form>
<?php include_once(G5_PATH.'/tail.php');?>
'PHP' 카테고리의 다른 글
[PHP] update.php (INSERT, UPDATE 처리)에서 사용했던 PHP 함수 (0) | 2023.03.09 |
---|---|
[PHP]update.php에서 코드짤 때 주의할 점 [INSERT, UPDATE 처리] (0) | 2023.03.03 |
[PHP]게시판 내 이동시 잘못된 주소로 들어오는 접속자들 걸러주기 (0) | 2023.03.03 |
[PHP]DB 결과값이 단수로 나올 때, 복수로 나올 때 쿼리 뽑기 함수 (0) | 2023.02.28 |
[PHP] 날짜 형태 변환 시 유의사항 (0) | 2023.02.21 |