본문 바로가기
아무리 생각해도 백임/php

[php, postgreSQL] 테이블에 저장, 조회

by seung_nari 2022. 6. 27.

등록

 

조회(지운건 제 전화번호라 ㅠㅠ)

 

상담경로 default 값을 5로 지정해줬는데 제대로 안 들어가네요 수정해야겠습니다.

 

* 수정할 목록

- 상담경로 값 안 들어가는 것

- 상담경로 값에 따라 문자 출력

- 고객코드 유효성 검사 및 신규 코드 발급


등록

index.php

<form action="insert.php" method="post">
    <input type="submit" value="고객정보 저장">
    <table class="customerinfo">
        <tr>
            <td><label for="c_no">고객코드</label></td>
            <td><input class="bg-color-gray" type="text" id="c_no" name="c_no"></td>
            <td><label for="c_name">고객명</label></td>
            <td><input type="text" id="c_name" name="c_name"></td>
            <td><label for="c_id">ID</label></td>
            <td><input type="text" id="c_id" name="c_id"></td>
            <td><label for="c_email">email</label></td>
            <td><input type="text" id="c_email" name="c_email"></td>
        </tr>
        <tr>
            <td><label for="c_tel">전화번호</label></td>
            <td><input type="text" id="c_tel" name="c_tel"></td>
            <td><label for="c_phone">* 핸드폰</label></td>
            <td><input type="text" id="c_phone" name="c_phone"></td>
            <td colspan="4"></td>
        </tr>
        <tr>
            <td><label for="c_addr">주소</label></td>
            <td colspan="7"></td>
        </tr>
    </table>
</form>

post 처리하는 insert.php

<?php

/* DB 접속 */
include "../inc/dbconn.php";

$c_no = $_POST['c_no'];
$c_name = $_POST['c_name'];
$c_id = $_POST['c_id'];
$c_tel = $_POST['c_tel'];
$c_phone = $_POST['c_phone'];
$c_email = $_POST['c_email'];

$sql = "INSERT INTO customer (no, name, id, regdate, tel, phone, email) values ('$c_no', '$c_name', '$c_id', (select current_date as today), '$c_tel', '$c_phone', '$c_email')";
$result = pg_query($conn, $sql);

if($result === false){
    echo '데이터 저장에 실패했습니다.';
    error_log(pg_errormessage($conn)); // 에러 로그 기록
} else {
    echo '저장 성공';
}

/* DB 연결 종료 */
pg_close($conn);

?>

출력

index.php

<table class="customerinfo">
    <tr class="bg-color-gray">
        <td>NO</td>
        <td>상담경로</td>
        <td>고객명</td>
        <td>고객CID</td>
        <td>고객HP</td>
        <td>상담일자</td>
        <td>상담주제</td>
        <td>상담원</td>
    </tr>

    <?php
        /* DB 접속 */
        include "../inc/dbconn.php";

        $sql = "select cons.seq_consulting as no, cons.root as root, cust.name as cust_name, cons.cid as cid, cust.tel as tel, cons.regdate as regdate, cons.summary as summary, cons.name as cons_name from consulting cons right join customer as cust on cust.phone = cons.cid where cons.seq_consulting is not null";
        $result = pg_query($conn, $sql);

        $list = '';

        while($row = pg_fetch_array($result)){
            $list = $list."<tr><td>{$row['no']}</td><td>{$row['root']}</td><td>{$row['cust_name']}</td><td>{$row['cid']}</td><td>{$row['tel']}</td><td>{$row['regdate']}</td><td>{$row['summary']}</td><td>{$row['cons_name']}</td></tr>";

        }echo $list;
    ?>

</table>

댓글