Web Programming >> PHP Programming
|
[목차] |
제24장 쇼핑몰 만들기 2
4. 회원용 주문 처리 프로그램 필요한 프로그램들 다음과 같다. / -- shop/ -- admin/ --- member/ --(회원관리 추가) | | | | | +-- list.html | | +-- viewbody.html | | +-- modifyform.html | | +-- modify.html | | +-- deleteform.html | | +-- delete.html | +- menu.html (관리자 메뉴 수정) +-- menu.html (쇼핑몰 메뉴 수정) | +-- registerform.html (회원가입 폼) +-- register.html (회원가입 처리) +-- check_id.html (ID 중복확인 프로그램) +-- login.html (로그인 폼) +-- login_process.html (로그인 처리) +-- logout.html (접속 종료) | +-- order.html (주문자 신상명세 입력화면) +-- confirm.html (주문처리 프로그램)
1. 테이블 수정하기 고객 정보를 저장하는 sold테이블에 회원 아이디를 저장할 필드를 추가한다. ALTER TABLE sold ADD id VARCHAR (15);
2. 주문처리 프로그램 파일명 : order.hrml <? session_start();
include "./user_function.html"; include "./dbconn.html";
if(!$user_uid) { echo ("<meta http-equiv='Refresh' content='0; URL=welcome.html'>"); exit; }
if($task != "order") { echo ("<meta http-equiv='Refresh' content='0; URL=welcome.html'>"); exit; }
?> <html> <head> <title>온라인 쇼핑몰</title> <style type="text/css"> <!-- a:link,a:visited,a:active { text-decoration : none; } a:hover { text-decoration : none; color : red; } TABLE, TD, TR, TH { font-size : 10pt; } //--> </style>
</head> <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red"> <form name="signform" method="POST" action="confirm.html"> <p> <div align="center"><table border="0" cellpadding="0" width="500"> <tr> <td width="500"><font size="3"><b>상품 배달 주소 및 상품 확인</b></td> </tr> <tr> <td width="500"><p align="left"> </p> <p align="right"><b>주문번호 : <?echo("$user_uid");?></b> <br> <p align="left">주문한 도서 목록입니다. <div align="center"><table border=1 width="500" bordercolor="white"> <tr> <td align="center" width="142" height="14" bgcolor="#70FFB9" bordercolor="green">상 품</td> <td align="center" width="142" height="14" bgcolor="#70FFB9" bordercolor="green">가 격</td> <td align="center" width="142" height="14" bgcolor="#70FFB9" bordercolor="green">수 량</td> <td align="center" width="142" height="14" bgcolor="#70FFB9" bordercolor="green">금 액</td> </tr> <? $query="SELECT uid,product_uid,amount,price FROM temp_bag WHERE user_uid = $user_uid"; $result = mysql_query($query); //echo("$query"); if (!$result) { error("QUERY_ERROR"); exit; } $rows = mysql_num_rows($result); $total_price = 0;
for($i=0;$i<$rows; $i++) { $sale_uid = (int)mysql_result($result,$i,0); $product_uid = (int)mysql_result($result,$i,1); $amount = (int)mysql_result($result,$i,2); $product_price = mysql_result($result,$i,3);
$total_price = ($product_price * $amount) + $total_price; $my_price = $product_price * $amount;
$query1="SELECT uid,name FROM product WHERE uid=$product_uid"; $result1 = mysql_query($query1); if (!$result1) { error("QUERY_ERROR"); exit; } $rows1 = mysql_num_rows($result); if($rows1 > 0) { $product_name = mysql_result($result1,0,1); } $product_price = number_format($product_price); $my_price = number_format($my_price); ?> <tr> <td align="center" width="142" height="16" bgcolor="#70FFB9" bordercolor="green"><?echo("$product_name");?></td> <td align="right" width="142" height="16" bordercolor="green"><?echo("$product_price");?></td> <td align="right" width="142" height="16" bordercolor="green"><?echo("$amount");?>개 </td> <td align="right" width="142" height="16" bordercolor="green"><?echo("$my_price");?>원 </td> </tr> <? } $total_price = number_format($total_price);
$query = "SELECT name,id,email,address,tel FROM member WHERE id = '$user_id'"; $result = mysql_query($query,$dbconn); if(!$result) { $errNO = mysql_errno($dbconn); $errMSG = mysql_error($dbconn);
echo("에러코드 $errNO : $errMSG<br>"); exit; }
$my_name = mysql_result($result,0,0); $my_id = mysql_result($result,0,1); $my_email = mysql_result($result,0,2); $my_address = mysql_result($result,0,3); $my_tel = mysql_result($result,0,4);
?> </table><br> <p align="right"><b>총합 : <?echo("$total_price");?> 원</b> </div> </p> <p align="left">배달 주소를 입력해 주세요. <div align="center"><table border width="500" bordercolor="white"> <tr> <td align="center" width="120" bgcolor="#70FFB9" bordercolor="green">이 름 </td> <td width="380"><p><input type="text" name="name" size="15" value="<?echo("$my_name");?>"></td> </tr> <tr> <td align="center" width="120" bgcolor="#70FFB9" bordercolor="green">ID </td> <td width="380"><p><input type="hidden" name="id" size="15" value="<?echo("$my_id");?>"> <?echo("$my_id");?></td> </tr> <tr> <td align="center" width="120" bgcolor="#70FFB9" bordercolor="green">연락처(전화번호)</td> <td width="380"><p><input type="text" name="phone" size="15" value="<?echo("$my_tel");?>"></td> </tr> <tr> <td align="center" width="120" bgcolor="#70FFB9" bordercolor="green">배달 주소</td> <td width="380"><p><input type="text" name="address" size="50" value="<?echo("$my_address");?>"></td> </tr> <tr> <td align="center" width="120" bgcolor="#70FFB9" bordercolor="green">전하는 말</td> <td width="380"><p align="left"><textarea name="desp" rows="4" cols="50"></textarea></td> </tr> </table></div> <p> </td> </tr> <tr> <td width="500" align="center"><font face="굴림"> <input type="submit" name="smbuit" value="확인"><font face="굴림"> <input type="reset" name="reset" value="다시작성"></td> </tr> </table></div> <p> </p></form> </body> </html>
파일명 : confirm.hrml <? session_start();
include "./user_function.html"; include "./dbconn.html";
$query="SELECT uid FROM temp_bag WHERE user_uid = $user_uid"; $result = mysql_query($query); if (!$result) { error("QUERY_ERROR"); exit; } $rows = mysql_num_rows($result);
if(!$rows) { ?> <script language="javascript"> <!-- window.alert('주문한 내용이 없습니다.') history.go(-1) --> </script> <? exit; }
if($name == "" || $phone=="" || $address =="") { ?> <script language="javascript"> <!-- window.alert('고객 입력사항 중 빠진 부분이 있습니다.\n확인하시고 빠진 부분을 입력하세요.') history.go(-1) --> </script>
<? exit; }
$signdate = time();
$query="SELECT uid FROM sold WHERE uid=$user_uid"; $result = mysql_query($query);
if (!$result) { error("QUERY_ERROR"); exit; } $rows = mysql_num_rows($result);
if(!$rows) { $query = "INSERT INTO sold (uid,name,phone,address,desp,status,signdate,id) "; $query .= "VALUES ($user_uid,'$name','$phone','$address','$desp','1',$signdate,'$id')"; $result = mysql_query($query); // echo("$query");
if (!$result) { error("QUERY_ERROR"); exit; } } else { ########## 사용자가 입력양식에 입력한대로 회원정보를 갱신한다.########## $query = "UPDATE sold SET name ='$name', phone = '$phone', address = '$address',"; $query .= "desp = '$desp',status='1',signdate=$signdate,id='$id' WHERE uid = $user_uid";
echo("$query");
$result = mysql_query($query); if(!$result) { error("QUERY_ERROR"); exit; } }
if($to == "") $to = "webmaster@leelab.co.kr";
$subject = "온라인 주문 신청서"; $from = "jklee@leelab.co.kr"; $rn = "jklee@leelab.co.kr"; $body = " <style type=\"text/css\"> a:link,a:visited,a:active { text-decoration : none; } a:hover { text-decoration : none; color : red; } TABLE, TD, TR, TH { font-size : 10pt; } </style> <div align='center'><table border='0' cellpadding='0' width='600'> <tr> <td width='600'><p align='center'><font size='3'><b>상품 주문서 확인</b></td> </tr> <tr> <td width='600'><p> </p> <p align='right'><b>주문번호 : ".$user_uid."</b> <br> <p align='left'>상품 갯수 확인 <div align='center'><table border width='500' bordercolor=\"white\"> <tr> <td align='center' width='142' height='14' bgcolor=\"#70FFB9\" bordercolor=\"green\">상 품</td> <td align='center' width='142' height='14' bgcolor=\"#70FFB9\" bordercolor=\"green\">단 가</td> <td align='center' width='142' height='14' bgcolor=\"#70FFB9\" bordercolor=\"green\">수 량</td> <td align='center' width='142' height='14' bgcolor=\"#70FFB9\" bordercolor=\"green\">금 액</td> </tr>"; $query="SELECT uid,product_uid,amount,price FROM temp_bag WHERE user_uid = $user_uid"; $result = mysql_query($query); //echo("$query"); if (!$result) { error("QUERY_ERROR"); exit; } $rows = mysql_num_rows($result); $total_price = 0; $body_phone = "신청하신 사항은 ";
for($i=0;$i<$rows; $i++) { $sale_uid = (int)mysql_result($result,$i,0); $product_uid = (int)mysql_result($result,$i,1); $amount = (int)mysql_result($result,$i,2); $product_price = (int)mysql_result($result,0,3); $my_total_price = $product_price * $amount; $total_price = $my_total_price + $total_price;
$query1="SELECT uid,name FROM product WHERE uid=$product_uid"; $result1 = mysql_query($query1);
if (!$result1) { error("QUERY_ERROR"); exit; } $product_name = mysql_result($result1,0,1);
$query2 = "INSERT INTO sale_bag (product_uid,user_uid,price,amount) "; $query2 .= "VALUES ($product_uid,'$user_uid',$product_price,$amount)"; $result2 = mysql_query($query2); if (!$result2) { error("QUERY_ERROR"); exit; }
$query2 = "DELETE FROM temp_bag where uid = $sale_uid"; $result2 = mysql_query($query2); if (!$result2) { error("QUERY_ERROR"); exit; } $product_price = number_format($product_price); $my_total_price = number_format($my_total_price);
$body_phone .= $product_name."은 ".$amount."개 입니다.";
$body .= " <tr> <td align=\"center\" width='142' height='16' bgcolor=\"#70FFB9\" bordercolor=\"green\">".$product_name."</td> <td align=\"right\" width='142' height='16'bordercolor=\"green\">".$product_price."</td> <td align=\"right\" width='142' height='16'bordercolor=\"green\">".$amount."개</td> <td align=\"right\" width='142' height='16'bordercolor=\"green\">".$my_total_price."</td> </tr>"; }
$query="SELECT uid,name,phone,address,desp FROM sold WHERE uid=$user_uid"; $result = mysql_query($query);
if (!$result) { error("QUERY_ERROR"); exit; } $name = mysql_result($result,0,1); $phone = mysql_result($result,0,2); $address = mysql_result($result,0,3); $desp = mysql_result($result,0,4);
$body_phone .= "신청자의 성명은".$name."이고, 주소는".$address."입니다. 전화번호는 ".$phone."입니다.남기신글은 ";
if($desp == "") $body_phone .= "없습니다."; else $body_phone .= $desp."입니다.";
$total_price = number_format($total_price);
$body .= " </table><br> <p align='right'><b>총합 : ".$total_price." 원</b> </div> <p align='center'> </p> <p align='left'>배달 주소 확인 <div align='center'><table border width='500' bordercolor=\"white\"> <tr> <td align='center' width='120' bgcolor=\"#70FFB9\" bordercolor=\"green\">이 름</td> <td width='380' bordercolor=\"green\"><p> ".$name."</td> </tr> <tr> <td align='center' width='120' bgcolor=\"#70FFB9\" bordercolor=\"green\">연락처(전화번호)</td> <td width='380' bordercolor=\"green\"><p> ".$phone."</td> </tr> <tr> <td align='center' width='120' bgcolor=\"#70FFB9\" bordercolor=\"green\">배달 주소 </td> <td width='380' bordercolor=\"green\"><p> ".$address."</td> </tr> <tr> <td align='center' width='120' height='23' bgcolor=\"#70FFB9\" bordercolor=\"green\">E-mail</td> <td width='380' height='23' bordercolor=\"green\"><p> ".$email."</td> </tr> <tr> <td align='center' width='120' height='95' bgcolor=\"#70FFB9\" bordercolor=\"green\">전하는 말</td> <td width='380' height='95' bordercolor=\"green\"><palign='left'> ".$desp."</td> </tr> </table></div> <p> </td> </tr> <tr> <td width='600'><p align='center'><font face='굴림'></td> </tr> <tr> <td width='600'><p><font face='굴림'><hr width='80%' with='80%'></td> </tr> <tr> <td width='600'><p align='center'><font face='굴림' size='2'>Copyrightⓒ 2000 <a href='mailto:jklee@leelab.co.kr'><font face='굴림' size='2'><b>LeeLAB's 온라인 서점</b></a> <font face='굴림' size='2'> All Rights Reserved.<br></td> </tr> </table></div>";
$mailheaders .= "Return-Path: $from\r\n"; $mailheaders .= "From: $rn <$from>\r\n"; $mailheaders .= "X-Mailer: Gfew Interface\r\n"; $mailheaders .= "Content-Type: text/html; charset=euc-kr\r\n";
$bodytext = stripslashes($body);
mail($to,$subject,$bodytext,$mailheaders); ?>
<html> <head> <title>온라인 주문 신청서</title> </head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red"> <? echo("$body"); ?>
<p> </p> <center> <font size=2> <a href="./main.html" >홈으로 돌아가기</a> </center> </body> </html> <? if($user_uid) { $user_uid = null; $HTTP_SESSION_VARS["user_uid"] = null; } ?>
많은 부분에서 버그가 나타나고 있습니다. 수정후 자료실에 올려 주시면, 참고하여 , 다시 올리겠습니다.
|
[목차] |