[-문구-Compeople-문구-]

++ETC/Study2014. 4. 14. 21:22

* write.htm [입력폼]

<form name=member_input method=post action=member_input_proc.php>
 아이디 : <input type=text name=id size=10> <br>
 이름 : <input type=text name=name size=10> <br>
 비번 : <input type=password name=pass1 size=10> <br>
 비번확인 : <input type=password name=pass2 size=10> <br>
 휴대폰번호 :
 <select name=hp1>
  <option value="010" selected>010</option>
  <option value="011">011</option>
  <option value="017">017</option>
  <option value="019">019</option>
 </select>
 -<input type=text name=hp2 size=4>
 -<input type=text name=hp3 size=4>
 <br>
 <input type=submit name=in value='회원가입'>
</form>

 

* member_input_proc.php [저장 처리폼]

<?php
function msg_back($msg){
 echo "<script>
   window.alert('$msg');
   history.go(-1);
    </script>";
 exit;
}

function msg_go($msg,$go_uri){
 echo "<script>
   window.alert('$msg');
   location.href='$go_uri';
    </script>";
 exit;
}

$id = $_POST[id];
$name = $_POST[name];
$pass1 = $_POST[pass1];
$pass2 = $_POST[pass2];
$hp = $_POST[hp1]."-".$_POST[hp2]."-".$_POST[hp3];

if($id=="" || $name=="" || $pass1=="" || $pass2==""){
 msg_back("아이디, 이름, 비밀번호는 꼭 입력해야 합니다.");
}

if($pass1 != $pass2){
 msg_back("비밀번호가 틀렸습니다.");
}

$connect = mysql_connect("localhost", "scjc2", "scjc.ac.kr");
$select_db = mysql_select_db("scjc2", $connect);
$search_sql = "select id from member where id = '$id';";
$search_result = mysql_query($search_sql, $connect);
$search_row = mysql_fetch_array($search_result);
if($search_row[id]){
 msg_back("사용할수 없는 아이디 입니다.");
}


$connect = mysql_connect("localhost", "scjc2", "scjc.ac.kr");
$select_db = mysql_select_db("scjc2", $connect);

$sql = "insert into member values('','$id','$name','$pass1','$hp')";

$result = mysql_query($sql, $connect);

if($result){
 msg_go("회원가입 완료!!","write.html");
}else{
 msg_back("회원가입에 실패했습니다.");
}
?>

 

* list.php [목록페이지] / 페이지처리

<?php
//$connect = mysql_connect("localhost", "scjc2", "scjc.ac.kr");
//$select_db = mysql_select_db("scjc2", $connect);
include "connect.php";
$sql = "select * from member ORDER BY no DESC";
$result = mysql_query($sql, $connect);
$page=$_GET[page];
if(!$page){
 $page=1;
}
$view_record = 4;
$limit_start = $page * $view_record - $view_record;
$sql = "select * from member ORDER BY no DESC limit ";
$sql .= "$limit_start,$view_record";
$result = mysql_query($sql, $connect);

//$total = mysql_rum_rows($result);

?>
<table border=1>
 <tr>
  <td>번호</td><td>id</td><td>이름</td><td>비번</td><td>핸드폰</td>
 </tr>
<?
while($row=mysql_fetch_array($result)){
 echo "
 <tr>
  <td>$row[no]</td> <td>$row[id]</td> <td>$row[name]</td> <td>$row[pass]</td> <td>$row[hp]</td>
 </tr>\n";
}
?>
 <tr>
  <td colspan=5 align='right'><a href='./write.html'>[쓰기]</a></td>
 </tr>
</table>

111111

* list.php [목록페이지] / 페이지처리

<?php
//$connect = mysql_connect("localhost", "scjc2", "scjc.ac.kr");
//$select_db = mysql_select_db("scjc2", $connect);
include "connect.php";
$sql = "select * from member ORDER BY no DESC";
$result = mysql_query($sql, $connect);
$total = mysql_num_rows($result); //전체 레코드수

$page=$_GET[page];
if(!$page){
 $page=1;
}
echo "현재페이지번호 : $page";
$view_record = 4; // 한 화면 출력 데이터 수
$limit_start = $page * $view_record - $view_record;
$sql = "select * from member ORDER BY no DESC limit ";
$sql .= "$limit_start,$view_record";
$result = mysql_query($sql, $connect);
//echo "전체데이터개수 : $total";

$total_page = ceil($total/$view_record); // 전체 페이지수
?>
<table border=1>
 <tr>
  <td>번호</td><td>id</td><td>이름</td><td>비번</td><td>핸드폰</td>
 </tr>
<?
while($row=mysql_fetch_array($result)){
 echo "
 <tr>
  <td>$row[no]</td> <td>$row[id]</td> <td>$row[name]</td> <td>$row[pass]</td> <td>$row[hp]</td>
 </tr>\n";
}
?>
 <tr>
  <td colspan=5 align='right'><a href='./write.html'>[쓰기]</a></td>
 </tr>
</table>
<?
for($i=1;$i<=$total_page;$i++){
 if($i == $page){
  echo "$i";
 }
 else{
  echo " <a href=$PHP_SELF?page=$i>$i</a> ";
 }
}
?>

 

* connect.php [DB접속]

<?php
$connect = mysql_connect("localhost", "scjc2", "scjc.ac.kr");
$select_db = mysql_select_db("scjc2", $connect);
?>

*****

Posted by SC-Compeople