🔓데이터베이스/쇼핑몰 프로젝트

쇼핑몰 만들기(2)

하얀성 2023. 12. 15. 18:36

- 마이페이지: 2점

(닉네임과 이메일, 로그아웃 등을 할 수 있도록 했다.)

 

header.php 의 일부로 들어가 있음.

<div class="user-box">
            <p>닉네임 : <span><?php echo $_SESSION['user_name']; ?></span></p>
            <p>email : <span><?php echo $_SESSION['user_email']; ?></span></p>
            <a href="logout.php" class="delete-btn">로그아웃</a>
         </div>

- 부가기능(공지사항): 1점

(공지사항 등록과 갱신은 관라지페이지, 공지사항은 메인페이지에 나오도록 했다.)

 

home.php의 일부 (공지사항을 메인페이지에 업로드)

 <section class="announcement" style="position: absolute; top: 300px; left: 100px; z-index: 10;">
    <?php
    $select_posts = mysqli_query($conn, "SELECT * FROM `posts` ORDER BY created_at DESC LIMIT 1");
    if($post = mysqli_fetch_assoc($select_posts)){
        echo "<div class='post'>";
        echo "<h3>" . htmlspecialchars($post['title']) . "</h3>";
        echo "<p>" . nl2br(htmlspecialchars($post['content'])) . "</p>";
        echo "</div>";
    }
    ?>
</section>

 

admin_post.php (공지 업데이트)

<?php
$conn = mysqli_connect('localhost','root','apmsetup','shop_db');

session_start();

$admin_id = $_SESSION['admin_id'];

if(!isset($admin_id)){
   header('location:login.php');
}

if(isset($_POST['update_post'])){
    $title = mysqli_real_escape_string($conn, $_POST['title']);
    $content = mysqli_real_escape_string($conn, $_POST['content']);

    // 공지사항을 posts 테이블에 추가합니다.
    mysqli_query($conn, "INSERT INTO posts (title, content) VALUES ('$title', '$content')");
    // 추가적인 확인 필요: 오류 처리, 성공 메시지 등
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <!-- font awesome cdn link  -->

    <!-- custom admin css file link  -->
    <link rel="stylesheet" href="css/admin_style.css">
    <style>
        /* admin_style.css */

/* 공지사항 업데이트 폼 기본 스타일 */
.update-post-form {
    width: 100%; /* 전체 너비 사용 */
    max-width: 700px; /* 최대 너비 설정 */
    margin: 30px auto; /* 상하 30px, 좌우 자동 (가운데 정렬) */
    padding: 20px; /* 내부 여백 */
    background: #fff; /* 배경색 */
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1); /* 그림자 효과 */
    border-radius: 5px; /* 모서리 둥글게 */
}

.update-post-form input[type="text"],
.update-post-form textarea {
    width: 100%; /* 전체 너비 사용 */
    padding: 10px; /* 패딩 */
    margin-bottom: 20px; /* 하단 여백 */
    border: 1px solid #ccc; /* 테두리 */
    border-radius: 5px; /* 모서리 둥글게 */
}

.update-post-form textarea {
    height: 200px; /* 텍스트 영역 높이 */
    resize: vertical; /* 세로 크기 조절 가능 */
}

.update-post-form button {
    padding: 10px 30px; /* 상하 10px, 좌우 30px 패딩 */
    border: none; /* 테두리 없음 */
    background: #333; /* 배경색 */
    color: #fff; /* 글자색 */
    font-size: 16px; /* 글자 크기 */
    cursor: pointer; /* 커서 모양 */
    border-radius: 5px; /* 모서리 둥글게 */
}

.update-post-form button:hover {
    background: #555; /* 호버시 배경색 변경 */
}

    </style>
    <title>공지사항</title>
</head>
<body>
    <?php include 'admin_header.php'; ?>

    <!-- 공지사항 업데이트 폼 -->
    <form action="admin_post.php" method="post" class="update-post-form">
        <input type="text" name="title" placeholder="공지 제목" required>
        <textarea name="content" placeholder="공지 내용" required></textarea>
        <button type="submit" name="update_post">공지 업데이트</button>
    </form>

    <script src="js/admin_script.js"></script>
</body>
</html>

- 포인트 적립 및 사용 기능: 3점

(라면 주문 갯수당 10점씩 쌓이도록 했다.)

 

admin_orders.php

<?php

$conn = mysqli_connect('localhost','root','apmsetup','shop_db');

session_start();

$admin_id = $_SESSION['admin_id'];

if(!isset($admin_id)){
   header('location:login.php');
}

if(isset($_POST['update_order'])){
   $order_update_id = $_POST['order_id'];
   $update_payment = $_POST['update_payment'];

   // 주문의 총 상품 수를 가져옵니다.
   $order_query = mysqli_query($conn, "SELECT total_products FROM `orders` WHERE id = '$order_update_id'");
   $order_data = mysqli_fetch_assoc($order_query);
   $total_products_str = $order_data['total_products'];

   // 상품 수량을 파싱합니다. "1x2,2x1,3x4" 형태의 문자열을 예로 듭니다.
   $product_quantities = explode(',', $total_products_str); // 각 상품 분리
   $total_quantity = 10;

   foreach ($product_quantities as $product_quantity) {
       $parts = explode('x', $product_quantity); // 상품 ID와 수량 분리
       $quantity = (int)$parts[1]; // 수량 추출
       $total_quantity += ($quantity+10); // 총 수량에 추가
   }

   // 포인트를 계산합니다.
   $points = $total_quantity;

   // 결제 상태와 포인트를 업데이트합니다.
   mysqli_query($conn, "UPDATE `orders` SET payment_status = '$update_payment', points = '$points' WHERE id = '$order_update_id'");
   $message[] = ' 결제 상태가 변경되었습니다!';
}

if(isset($_GET['delete'])){
   $delete_id = $_GET['delete'];
   mysqli_query($conn, "DELETE FROM `orders` WHERE id = '$delete_id'");
   header('location:admin_orders.php');
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>orders</title>

   <!-- font awesome cdn link  -->

   <!-- custom admin css file link  -->
   <link rel="stylesheet" href="css/admin_style.css">

</head>
<body>
   
<?php include 'admin_header.php'; ?>

<section class="orders">

   <h1 class="title">총 주문목록</h1>

   <div class="box-container">
      <?php
      $select_orders = mysqli_query($conn, "SELECT * FROM `orders`");
      if(mysqli_num_rows($select_orders) > 0){
         while($fetch_orders = mysqli_fetch_assoc($select_orders)){
      ?>
      <div class="box">
         <p> 유저 넘버 : <span><?php echo $fetch_orders['user_id']; ?></span> </p>
         <p> 주문날짜 : <span><?php echo $fetch_orders['placed_on']; ?></span> </p>
         <p> 닉네임 : <span><?php echo $fetch_orders['name']; ?></span> </p>
         <p> 전화번호 : <span><?php echo $fetch_orders['number']; ?></span> </p>
         <p> email : <span><?php echo $fetch_orders['email']; ?></span> </p>
         <p> 배송지 : <span><?php echo $fetch_orders['address']; ?></span> </p>
         <p> 주문 정보 : <span><?php echo $fetch_orders['total_products']; ?></span> </p>
         <p> 전체 주문가격  : <span><?php echo $fetch_orders['total_price']; ?></span> </p>
         <p> 지불 방식 : <span><?php echo $fetch_orders['method']; ?></span> </p>
         <p> 적립포인트 : <span><?php echo $fetch_orders['points']; ?></span> </p>
         <form action="" method="post">
            <input type="hidden" name="order_id" value="<?php echo $fetch_orders['id']; ?>">
            <select name="update_payment">
               <option value="" selected disabled><?php echo $fetch_orders['payment_status']; ?></option>
               <option value="미결제">미결제</option>
               <option value="결제완료">결제완료</option>
            </select>
            <input type="submit" value="수정" name="update_order" class="option-btn">
            <a href="admin_orders.php?delete=<?php echo $fetch_orders['id']; ?>" onclick="return confirm('주문을 제거하실건가요?');" class="delete-btn">삭제</a>
         </form>
      </div>
      <?php
         }
      }else{
         echo '<p class="empty">아직 주문이 없어요</p>';
      }
      ?>
   </div>

</section>


<!-- custom admin js file link  -->
<script src="js/admin_script.js"></script>

</body>
</html>

- 상품설명 페이지: 2점 

(shop.php에서  상품이름을 클릭하면 상세정보를 확인할 수 있다.)

 

사진 이미지 및 관련 정보, 영상을 추가할 경우 보이도록 했다.

 

shop.php(상품리스트)

<?php

$conn = mysqli_connect('localhost','root','apmsetup','shop_db');

session_start();

$user_id = $_SESSION['user_id'];

if(!isset($user_id)){
   header('location:login.php');
}

if(isset($_POST['add_to_cart'])){

   $product_name = $_POST['product_name'];
   $product_price = $_POST['product_price'];
   $product_image = $_POST['product_image'];
   $product_quantity = $_POST['product_quantity'];

   $check_cart_numbers = mysqli_query($conn, "SELECT * FROM `cart` WHERE name = '$product_name' AND user_id = '$user_id'") or die('query failed');

   if(mysqli_num_rows($check_cart_numbers) > 0){
      $message[] = '이미 장바구니에 담긴 상품이에요!';
   }else{
      mysqli_query($conn, "INSERT INTO `cart`(user_id, name, price, quantity, image) VALUES('$user_id', '$product_name', '$product_price', '$product_quantity', '$product_image')") or die('query failed');
      $message[] = '상품이 장바구니에 담겼습니다!';
   }

}

?>

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>shop</title>

   <!-- font awesome cdn link  -->

   <!-- custom css file link  -->
   <link rel="stylesheet" href="css/style.css">

</head>
<body>
   
<?php include 'header.php'; ?>

<div class="heading">
   <h3>상품 목록</h3>
   <p> <a href="home.php">홈으로 가기</a> </p>
</div>

<section class="products">
   <h1 class="title">상품 목록</h1>
   <div class="box-container">
      <?php  
         $select_products = mysqli_query($conn, "SELECT * FROM `products`");
         if(mysqli_num_rows($select_products) > 0){
            while($fetch_products = mysqli_fetch_assoc($select_products)){
      ?>
      <form action="" method="post" class="box">
         <img class="image" src="photo/<?php echo $fetch_products['image']; ?>" alt="">
         <!-- 상품 이름에 하이퍼링크 추가 -->
         <div class="name">
            <a href="product_detail.php?product_id=<?php echo $fetch_products['id']; ?>">
               <?php echo $fetch_products['name']; ?>
            </a>
         </div>
         <div class="price"><?php echo $fetch_products['price']; ?>원 + 10 포인트</div>
         <input type="number" min="1" name="product_quantity" value="1" class="qty">
         <input type="hidden" name="product_name" value="<?php echo $fetch_products['name']; ?>">
         <input type="hidden" name="product_price" value="<?php echo $fetch_products['price']; ?>">
         <input type="hidden" name="product_image" value="<?php echo $fetch_products['image']; ?>">
         <input type="submit" value="장바구니 담기" name="add_to_cart" class="btn">
      </form>
      <?php
            }
         }else{
            echo '<p class="empty">no products added yet!</p>';
         }
      ?>
   </div>
</section>








<?php include 'footer.php'; ?>

<!-- custom js file link  -->
<script src="js/script.js"></script>

</body>
</html>

 

 

product_detail.php 

<?php

$conn = mysqli_connect('localhost','root','apmsetup','shop_db');
session_start();

// URL에서 product_id 가져오기
$product_id = isset($_GET['product_id']) ? $_GET['product_id'] : '';

// 상품 정보를 가져오는 쿼리
$query = "SELECT * FROM `products` WHERE id='$product_id'";
$result = mysqli_query($conn, $query);

// 상품 정보가 존재하는 경우
if(mysqli_num_rows($result) > 0) {
    $product = mysqli_fetch_assoc($result);
    // 여기서 $product 변수에 상품의 정보가 담겨있습니다.
} else {
    // 상품 정보가 없는 경우
    echo "<p>상품을 찾을 수 없습니다.</p>";
    exit;
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title><?php echo $product['name']; ?></title>

   <!-- font awesome cdn link  -->

   <!-- custom css file link  -->
   <link rel="stylesheet" href="css/style.css">
    <style>
        /* 상품 이미지 스타일 */
.product-detail img {
    width: 33.33%; /* 이미지 크기를 1/3로 줄임 */
    margin-bottom: 20px; /* 이미지 아래 여백 추가 */
}

/* 비디오 컨트롤러 스타일 */
.product-detail video {
   max-width: 100%; /* 비디오가 컨테이너 너비를 초과하지 않도록 */
   height: auto; /* 비디오의 비율을 유지하면서 높이 조절 */
   margin-bottom: 20px; /* 비디오 아래 여백 추가 */
}
/* 상품 상세 정보 컨테이너 스타일 */
.product-detail {
   padding: 20px;
   background-color: #fff; /* 배경색 설정 */
   border-radius: 5px; /* 테두리 둥글게 */
   box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* 그림자 효과 */
   margin: 20px auto; /* 상단과 하단 여백 추가, 가운데 정렬 */
   max-width: 800px; /* 최대 너비 설정 */
}
/* 상품 설명 스타일 */
.product-detail p {
    font-size: 1.8rem; /* 글자 크기를 더 크게 조절 */
   text-align: justify; /* 양쪽 정렬 */
   line-height: 1.6; /* 줄간격 설정 */
   color: #333; /* 글자색 설정 */
   margin-bottom: 20px; /* 단락 아래 여백 추가 */
}
/* 상품 이름 스타일 */
.product-detail h2 {
    font-size: 3rem; /* 제목 글자 크기를 키움 */
   color: #c0392b; /* 제목 글자색 설정 */
   margin-bottom: 10px; /* 제목 아래 여백 추가 */
}

/* 가격 스타일 */
.product-detail .price {
    font-size: 2.8rem; /* 가격 글자 크기를 키움 */
   font-size: 24px; /* 글자 크기 설정 */
   font-weight: bold; /* 글자 굵기 설정 */
   color: #16a085; /* 글자색 설정 */
   margin-bottom: 20px; /* 가격 아래 여백 추가 */
}
    </style>
</head>
<body>

<?php include 'header.php'; ?>

<div class="product-detail">
    <h2><?php echo $product['name']; ?></h2>
    <img src="photo/<?php echo $product['image']; ?>" alt="<?php echo $product['name']; ?>">
    <p>가격: <?php echo $product['price']; ?></p>
    <?php if(!empty($product['video_url'])): ?>
        <video controls>
            <source src="<?php echo $product['video_url']; ?>" type="video/mp4">
            브라우저가 비디오를 지원하지 않습니다.
        </video>
    <?php endif; ?>
    <p>설명: <?php echo nl2br($product['description']); ?></p>
    <!-- 여기에 추가적인 상품 정보를 표시할 수 있습니다. -->
</div>

<?php include 'footer.php'; ?>

</body>
</html>

- 주문완료: 2점

(상품 장바구니에서 결제하러 가기를 누르면 아래처럼 주문 내역서 작성이 나온다. )

(주문 작성 완료 후, header의 주문확인을 누르면 주문 내역을 확인할 수 있다.)

 

 

 

checkout.php

<?php

$conn = mysqli_connect('localhost','root','apmsetup','shop_db');

session_start();

$user_id = $_SESSION['user_id'];

if(!isset($user_id)){
   header('location:login.php');
}

if(isset($_POST['order_btn'])){

   $name = mysqli_real_escape_string($conn, $_POST['name']);
   $number = $_POST['number'];
   $email = mysqli_real_escape_string($conn, $_POST['email']);
   $method = mysqli_real_escape_string($conn, $_POST['method']);
   $address = mysqli_real_escape_string($conn, 'flat no. '. $_POST['flat'].', '. $_POST['street'].', '. $_POST['city'].', '. $_POST['country'].' - '. $_POST['pin_code']);
   $placed_on = date('d-M-Y');

   $cart_total = 0;
   $cart_products[] = '';

   $cart_query = mysqli_query($conn, "SELECT * FROM `cart` WHERE user_id = '$user_id'");
   if(mysqli_num_rows($cart_query) > 0){
      while($cart_item = mysqli_fetch_assoc($cart_query)){
         $cart_products[] = $cart_item['name'].' ('.$cart_item['quantity'].') ';
         $sub_total = ($cart_item['price'] * $cart_item['quantity']);
         $cart_total += $sub_total;
      }
   }

   $total_products = implode(', ',$cart_products);

   $order_query = mysqli_query($conn, "SELECT * FROM `orders` WHERE name = '$name' AND number = '$number' AND email = '$email' AND method = '$method' AND address = '$address' AND total_products = '$total_products' AND total_price = '$cart_total'") or die('query failed');

   if($cart_total == 0){
      $message[] = '장바구니가 비었습니다.';
   }else{
      if(mysqli_num_rows($order_query) > 0){
         $message[] = '이미 주문한 상품입니다.';
      }else{
         mysqli_query($conn, "INSERT INTO `orders`(user_id, name, number, email, method, address, total_products, total_price, placed_on) VALUES('$user_id', '$name', '$number', '$email', '$method', '$address', '$total_products', '$cart_total', '$placed_on')");
         $message[] = '주문이 성공적으로 추가되었습니다!';
         mysqli_query($conn, "DELETE FROM `cart` WHERE user_id = '$user_id'");
      }
   }
   
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>checkout</title>

   <!-- font awesome cdn link  -->

   <!-- custom css file link  -->
   <link rel="stylesheet" href="css/style.css">

</head>
<body>
   
<?php include 'header.php'; ?>

<div class="heading">
   <h3>주문 확인</h3>
   <p> <a href="home.php">홈으로 가기</a></p>
</div>

<section class="display-order">

   <?php  
      $grand_total = 0;
      $select_cart = mysqli_query($conn, "SELECT * FROM `cart` WHERE user_id = '$user_id'");
      if(mysqli_num_rows($select_cart) > 0){
         while($fetch_cart = mysqli_fetch_assoc($select_cart)){
            $total_price = ($fetch_cart['price'] * $fetch_cart['quantity']);
            $grand_total += $total_price;
   ?>
   <p> <?php echo $fetch_cart['name']; ?> <span>: <?php echo '최저 '.$fetch_cart['price'].'원'.' x '. $fetch_cart['quantity']; ?></span> </p>
   <?php
      }
   }else{
      echo '<p class="empty">장바구니가 비어있습니다.</p>';
   }
   ?>
   <div class="grand-total"> 합계 : <span><?php echo $grand_total; ?></span> </div>

</section>

<section class="checkout">

   <form action="" method="post">
      <h3>주문 내역서 작성</h3>
      <div class="flex">
         <div class="inputBox">
            <span>닉네임 :</span>
            <input type="text" name="name" required placeholder="닉네임">
         </div>
         <div class="inputBox">
            <span>전화번호 :</span>
            <input type="number" name="number" required placeholder="전화번호">
         </div>
         <div class="inputBox">
            <span>email :</span>
            <input type="email" name="email" required placeholder="email">
         </div>
         <div class="inputBox">
            <span>결제 방식 :</span>
            <select name="method">
               <option value="무통장 입금">무통장 입금</option>
               <option value="신용카드">신용카드</option>
               <option value="네이버페이">네이버페이</option>
            </select>
         </div>
         <div class="inputBox">
            <span>도로명 주소 :</span>
            <input type="number" min="0" name="flat" required placeholder="창이대로 423">
         </div>
         <div class="inputBox">
            <span>상세 주소 :</span>
            <input type="text" name="street" required placeholder="e.x) 200호">
         </div>
         <div class="inputBox">
            <span> 도 :</span>
            <input type="text" name="state" required placeholder="e.x) 경상남도">
         </div>
         <div class="inputBox">
            <span>시,군 :</span>
            <input type="text" name="city" required placeholder="e.x) 창원시">
         </div>
         <div class="inputBox">
            <span>국적 :</span>
            <input type="text" name="country" required placeholder="e.x) 대한민국">
         </div>
         <div class="inputBox">
            <span>주문 pin번호 :</span>
            <input type="number" min="0" name="pin_code" required placeholder="e.x) 123456">
         </div>
      </div>
      <input type="submit" value="주문하기" class="btn" name="order_btn">
   </form>

</section>


<?php include 'footer.php'; ?>

<!-- custom js file link  -->
<script src="js/script.js"></script>

</body>
</html>

 

orders.php

<?php

$conn = mysqli_connect('localhost','root','apmsetup','shop_db');

session_start();

$user_id = $_SESSION['user_id'];

if(!isset($user_id)){
   header('location:login.php');
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>주문하기</title>

   <!-- font awesome cdn link  -->

   <!-- custom css file link  -->
   <link rel="stylesheet" href="css/style.css">

</head>
<body>
   
<?php include 'header.php'; ?>

<div class="heading">
   <h3>주문 확인</h3>
   <p> <a href="home.php">홈으로 가기</a></p>
</div>

<section class="placed-orders">

   <h1 class="title">주문 내역</h1>

   <div class="box-container">

      <?php
         $order_query = mysqli_query($conn, "SELECT * FROM `orders` WHERE user_id = '$user_id'");
         if(mysqli_num_rows($order_query) > 0){
            while($fetch_orders = mysqli_fetch_assoc($order_query)){
      ?>
      <div class="box">
         <p> 주문날짜 : <span><?php echo $fetch_orders['placed_on']; ?></span> </p>
         <p> 닉네임 : <span><?php echo $fetch_orders['name']; ?></span> </p>
         <p> 전화번호 : <span><?php echo $fetch_orders['number']; ?></span> </p>
         <p> email : <span><?php echo $fetch_orders['email']; ?></span> </p>
         <p> 배송지 : <span><?php echo $fetch_orders['address']; ?></span> </p>
         <p> 지불 방식 : <span><?php echo $fetch_orders['method']; ?></span> </p>
         <p> 주문 정보 : <span><?php echo $fetch_orders['total_products']; ?></span> </p>
         <p> 전체 주문가격 : <span><?php echo $fetch_orders['total_price']; ?></span> </p>
         <p> 거래 상황 : <span style="color:<?php if($fetch_orders['payment_status'] == '거래대기'){ echo 'red'; }else{ echo 'green'; } ?>;"><?php echo $fetch_orders['payment_status']; ?></span> </p>
         </div>
      <?php
       }
      }else{
         echo '<p class="empty">아직 주문이 없어요</p>';
      }
      ?>
   </div>

</section>



<?php include 'footer.php'; ?>

<!-- custom js file link  -->
<script src="js/script.js"></script>

</body>
</html>

 

admin_orders.php

<?php

$conn = mysqli_connect('localhost','root','apmsetup','shop_db');

session_start();

$admin_id = $_SESSION['admin_id'];

if(!isset($admin_id)){
   header('location:login.php');
}

if(isset($_POST['update_order'])){
   $order_update_id = $_POST['order_id'];
   $update_payment = $_POST['update_payment'];

   // 주문의 총 상품 수를 가져옵니다.
   $order_query = mysqli_query($conn, "SELECT total_products FROM `orders` WHERE id = '$order_update_id'");
   $order_data = mysqli_fetch_assoc($order_query);
   $total_products_str = $order_data['total_products'];

   // 상품 수량을 파싱합니다. "1x2,2x1,3x4" 형태의 문자열을 예로 듭니다.
   $product_quantities = explode(',', $total_products_str); // 각 상품 분리
   $total_quantity = 10;

   foreach ($product_quantities as $product_quantity) {
       $parts = explode('x', $product_quantity); // 상품 ID와 수량 분리
       $quantity = (int)$parts[1]; // 수량 추출
       $total_quantity += ($quantity+10); // 총 수량에 추가
   }

   // 포인트를 계산합니다.
   $points = $total_quantity;

   // 결제 상태와 포인트를 업데이트합니다.
   mysqli_query($conn, "UPDATE `orders` SET payment_status = '$update_payment', points = '$points' WHERE id = '$order_update_id'");
   $message[] = ' 결제 상태가 변경되었습니다!';
}

if(isset($_GET['delete'])){
   $delete_id = $_GET['delete'];
   mysqli_query($conn, "DELETE FROM `orders` WHERE id = '$delete_id'");
   header('location:admin_orders.php');
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>orders</title>

   <!-- font awesome cdn link  -->

   <!-- custom admin css file link  -->
   <link rel="stylesheet" href="css/admin_style.css">

</head>
<body>
   
<?php include 'admin_header.php'; ?>

<section class="orders">

   <h1 class="title">총 주문목록</h1>

   <div class="box-container">
      <?php
      $select_orders = mysqli_query($conn, "SELECT * FROM `orders`");
      if(mysqli_num_rows($select_orders) > 0){
         while($fetch_orders = mysqli_fetch_assoc($select_orders)){
      ?>
      <div class="box">
         <p> 유저 넘버 : <span><?php echo $fetch_orders['user_id']; ?></span> </p>
         <p> 주문날짜 : <span><?php echo $fetch_orders['placed_on']; ?></span> </p>
         <p> 닉네임 : <span><?php echo $fetch_orders['name']; ?></span> </p>
         <p> 전화번호 : <span><?php echo $fetch_orders['number']; ?></span> </p>
         <p> email : <span><?php echo $fetch_orders['email']; ?></span> </p>
         <p> 배송지 : <span><?php echo $fetch_orders['address']; ?></span> </p>
         <p> 주문 정보 : <span><?php echo $fetch_orders['total_products']; ?></span> </p>
         <p> 전체 주문가격  : <span><?php echo $fetch_orders['total_price']; ?></span> </p>
         <p> 지불 방식 : <span><?php echo $fetch_orders['method']; ?></span> </p>
         <p> 적립포인트 : <span><?php echo $fetch_orders['points']; ?></span> </p>
         <form action="" method="post">
            <input type="hidden" name="order_id" value="<?php echo $fetch_orders['id']; ?>">
            <select name="update_payment">
               <option value="" selected disabled><?php echo $fetch_orders['payment_status']; ?></option>
               <option value="미결제">미결제</option>
               <option value="결제완료">결제완료</option>
            </select>
            <input type="submit" value="수정" name="update_order" class="option-btn">
            <a href="admin_orders.php?delete=<?php echo $fetch_orders['id']; ?>" onclick="return confirm('주문을 제거하실건가요?');" class="delete-btn">삭제</a>
         </form>
      </div>
      <?php
         }
      }else{
         echo '<p class="empty">아직 주문이 없어요</p>';
      }
      ?>
   </div>

</section>


<!-- custom admin js file link  -->
<script src="js/admin_script.js"></script>

</body>
</html>

회원가입: 2점

(두가지 버전으로 가입 가능하고, 로그인 화면과 연결.)

 

register.php

<?php

$conn = mysqli_connect('localhost','root','apmsetup','shop_db');

if(isset($_POST['submit'])){

   $name = mysqli_real_escape_string($conn, $_POST['name']);
   $email = mysqli_real_escape_string($conn, $_POST['email']);
   $pass = mysqli_real_escape_string($conn, md5($_POST['password']));
   $cpass = mysqli_real_escape_string($conn, md5($_POST['cpassword']));
   $user_type = $_POST['user_type'];

   $select_users = mysqli_query($conn, "SELECT * FROM `users` WHERE email = '$email' AND password = '$pass'");

   if(mysqli_num_rows($select_users) > 0){
      $message[] = '이미 등록되있는 유저입니다!';
   }else{
      if($pass != $cpass){
         $message[] = '비밀번호가 다릅니다';
      }else{
         mysqli_query($conn, "INSERT INTO `users`(name, email, password, user_type) VALUES('$name', '$email', '$cpass', '$user_type')");
         $message[] = '등록성공';
         header('location:login.php');
      }
   }

}

?>

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>등록하기</title>

   <!-- font awesome cdn link  -->

   <!-- custom css file link  -->
   <link rel="stylesheet" href="css/style.css">

</head>
<body>

   
<div class="form-container">

   <form action="" method="post">
      <h3>가입하기</h3>
      <input type="text" name="name" placeholder="닉네임" required class="box">
      <input type="email" name="email" placeholder="이메일주소" required class="box">
      <input type="password" name="password" placeholder="비밀번호" required class="box">
      <input type="password" name="cpassword" placeholder="비밀번호확인" required class="box">
      <select name="user_type" class="box">
         <option value="user">사용자버전</option>
         <option value="admin">관리자버전</option>
      </select>
      <input type="submit" name="submit" value="회원가입 신청" class="btn">
      <p>이미 계정이 있다면? <a href="login.php">로그인 하기</a></p>
   </form>

</div>

</body>
</html>

쇼핑백: 2점

(장바구니를 담는 공간 + 라면 리스트와 결제페이지로 잇도록 만들었다. 카트 아이콘을 통해 바로 들어가서 확인가능하다.)

장바구니에 담긴 상품수만큼 숫자가 증가하도록 했다.

 

cart.php(장바구니 페이지)

<?php

$conn = mysqli_connect('localhost','root','apmsetup','shop_db');

session_start();

$user_id = $_SESSION['user_id'];

if(!isset($user_id)){
   header('location:login.php');
}

if(isset($_POST['update_cart'])){
   $cart_id = $_POST['cart_id'];
   $cart_quantity = $_POST['cart_quantity'];
   mysqli_query($conn, "UPDATE `cart` SET quantity = '$cart_quantity' WHERE id = '$cart_id'");
   $message[] = 'cart quantity updated!';
}

if(isset($_GET['delete'])){
   $delete_id = $_GET['delete'];
   mysqli_query($conn, "DELETE FROM `cart` WHERE id = '$delete_id'");
   header('location:cart.php');
}

if(isset($_GET['delete_all'])){
   mysqli_query($conn, "DELETE FROM `cart` WHERE user_id = '$user_id'");
   header('location:cart.php');
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>cart</title>

   <!-- font awesome cdn link  -->

   <!-- custom css file link  -->
   <link rel="stylesheet" href="css/style.css">

</head>
<body>
   
<?php include 'header.php'; ?>

<div class="heading">
   <h3>장바구니</h3>
   <p> <a href="home.php">홈으로 가기</a> </p>
</div>

<section class="shopping-cart">

   <h1 class="title">상품 담기</h1>

   <div class="box-container">
      <?php
         $grand_total = 0;
         $select_cart = mysqli_query($conn, "SELECT * FROM `cart` WHERE user_id = '$user_id'");
         if(mysqli_num_rows($select_cart) > 0){
            while($fetch_cart = mysqli_fetch_assoc($select_cart)){  
      ?>
      <div class="box">
         <a href="cart.php?delete=<?php echo $fetch_cart['id']; ?>" class="fas fa-times" onclick="return confirm('장바구니에서 제거하실건가요?');"></a>
         <img src="photo/<?php echo $fetch_cart['image']; ?>" alt="">
         <div class="name"><?php echo $fetch_cart['name']; ?></div>
         <div class="price"><?php echo $fetch_cart['price']; ?>원 + 10포인트</div>
         <form action="" method="post">
            <input type="hidden" name="cart_id" value="<?php echo $fetch_cart['id']; ?>">
            <input type="number" min="1" name="cart_quantity" value="<?php echo $fetch_cart['quantity']; ?>">
            <input type="submit" name="update_cart" value="수정" class="option-btn">
         </form>
         <div class="sub-total"> 구매 가격 : <span><?php echo $sub_total = ($fetch_cart['quantity'] * $fetch_cart['price']); ?></span> </div>
      </div>
      <?php
      $grand_total += $sub_total;
         }
      }else{
         echo '<p class="empty">장바구니가 비어있어요</p>';
      }
      ?>
   </div>

   <div style="margin-top: 2rem; text-align:center;">
      <a href="cart.php?delete_all" class="delete-btn <?php echo ($grand_total > 1)?'':'disabled'; ?>" onclick="return confirm('장바구니에서 모두 지울건가요?');">전체 삭제</a>
   </div>

   <div class="cart-total">
      <p>총 결제액 : <span><?php echo $grand_total; ?></span></p>
      <div class="flex">
         <a href="shop.php" class="option-btn">라면 더 담으러가기</a>
         <a href="checkout.php" class="btn <?php echo ($grand_total > 1)?'':'disabled'; ?>">결제하러 가기</a>
      </div>
   </div>

</section>








<?php include 'footer.php'; ?>

<!-- custom js file link  -->
<script src="js/script.js"></script>

</body>
</html>

 


'🔓데이터베이스 > 쇼핑몰 프로젝트' 카테고리의 다른 글

쇼핑몰 기능 확인 영상  (0) 2023.12.15
쇼핑몰 만들기(3)  (0) 2023.12.15
쇼핑몰 개략도  (0) 2023.12.13
쇼핑몰 만들기  (0) 2023.12.10
프로젝트 쇼핑몰 만들기  (0) 2023.12.05