U E D R , A S I H C RSS

2010php/방명록만들기

Difference between r1.7 and the current

@@ -38,26 +38,64 @@
echo($obj->name);
?>
}}}
== 기본 화면 (index.php) ==
== 입출력 최종 완성 (9월 8일) ==
= 메인화면 ( index.php ) =
{{{
<html>
<head><title>방명록</title><head>
<head> 
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>방명록</title> 
<?php
include "dbconnect.php";
?>
<head>
<body>
<form method='post' action='output.php'>
<form method='post' action='process.php'>

이름  <input type='text' name='input_name' size='10'>    
이름  <input type='text' name='input_name' maxlength='10' size='10'>    
비밀번호  <input type="password" name='input_pw'size='4' maxlength='4'>
<br>
<input type = "radio" name = "status" value = "1" size = "40" checked><img src="http://cfile234.uf.daum.net/image/152622034C88B1DC682870">
<input type = "radio" name = "status" value = "2" size = "40"><img src="http://cfile223.uf.daum.net/image/162622034C88B1DC696BEC">
<input type = "radio" name = "status" value = "3" size = "40"><img src="http://cfile206.uf.daum.net/image/142622034C88B1DC6AA52F">
<input type = "radio" name = "status" value = "4" size = "40"><img src="http://cfile232.uf.daum.net/image/152622034C88B1DC6BFF47">
<input type = "radio" name = "status" value = "5" size = "40"><img src="http://cfile234.uf.daum.net/image/162622034C88B1DC6C0395">
<br>
<textarea name='context' rows='4' cols='50'></textarea>
<br>
<input type='submit' value=' 전송 '>
<input type='submit' value='전송'> 
</form>
 
<?
include "print.php";
?>
</body>
</html>
}}}
== 글자 수 제한의 처리 (process.php) ==
== 데이터베이스에 연결 ( dbconnect.php ) ==
{{{
<?
<?php
$dbconn = mysql_connect("intra.zeropage.org", "csephp", "2010php");
$tableconn = mysql_select_db("csephp_db", $dbconn);
?>
}}}
== 쿼리를 만들때 시간을 저장하기 위해.. ( get_time.php ) ==
{{{
<?php
$unix_ts=mktime();
$date=date('Y-m-d', $unix_ts);
?>
}}}
== 모든 처리는 여기서... ( process.php ) ==
{{{
<?php
include "dbconnect.php";
/*********************
* 쿼리를
* 만듭니다.
*********************/
//이름 입력의 처리
if (strlen($_POST['input_name']) > 10 )
{
@@ -87,42 +125,93 @@
{
$posted_context = $_POST['context'];
}
$posted_status = $_POST['status'];
include "get_time.php";
$query = "insert into guest (name, pw, status, contents, date) values ('$posted_name', '$posted_pw', '$posted_status', '$posted_context', '$date')";
/*********************
* 쿼리를 전송
* 합니다.
*********************/
if(($posted_name!="")&&($posted_pw!="")&&($posted_pw!=""))
{
$result = mysql_query($query, $dbconn);
}
header("location:index.php");
?>
}}}
== 입력 받은 내용 출력 (output.php) ==
== 입력을 받고, 출력(페이지 추가) ( print.php ) ==
{{{
<?php
$query = "select * from guest ORDER BY no DESC";
$result = mysql_query($query, $dbconn);
$record_number = mysql_num_rows($result);
$scale = 10;//한 페이지당 글 수
 
//전체 페이지( $total_page ) 계산
if( $record_number % $scale == 0)
$total_page = floor($record_number / $scale );
else
$total_page = floor($record_number / $scale) + 1;
 
if(!$page) $page = 1;
 
//페이지에 따라 $start 계산
$start = ($page -1) * $scale;
 
 
for( $i = $start; $i < $start + $scale && $i < $record_number; $i++){
include "get_record.php";
 
echo("<br>기본정보 : $name $no $pw $status $date <br>");
echo("내 용 : $contents <br>");
include "print_status.php";
 
}
 
for( $i=1; $i<=$total_page; $i++){
if($page == $i){
echo" <b>[$i]</b>";
}
else{
echo"<a href='index.php?page=$i'>[$i]</a>";
}
}
?>
}}}
 
== 출력을 위해 필요함 ( get_record.php ) ==
{{{
<html><head><title></title></head><body>
<?
include_once("process.php");
echo("입력받은 이름 : ".$_POST['input_name']."<br>");
echo("입력받은 비번 : ".$_POST['input_pw']."<br>");
echo("입력받은 내용 : ".$_POST['context']."<br>");
echo("<br>");
echo("출력된 이름(10byte) : ".$posted_name."<br>");
echo("출력된 비번(04byte) : ".$posted_pw."<br>");
echo("출력된 내용(2000byte) : ".$posted_context."<br>");
$name=mysql_result($result,$i,0);
$no=mysql_result($result,$i,1);
$pw=mysql_result($result,$i,2);
$contents=mysql_result($result,$i,3);
$status=mysql_result($result,$i,4);
$date=mysql_result($result,$i,5);
?>
</body>
</html>
}}}
== 오늘의 상태 == 
나머지 부분은 생략
기본화면에 첨부하면 되므로..ㅋ
== 오늘의 상태 (print_status.php) ==
{{{
<html>
<head><title>방명록</title><head> 
<;body>
.
.
<input type = "radio" name = "state" value = "1" size = "40" checked><img src="1.jpg"> 
<input type = "radio" name = "state" value = "2" size = "40"><img src="2.jpg"> 
<input type = "radio" name = "state" value = "3" size = "40"><img src="3.jpg"> 
<input type = "radio" name = "state" value = "4" size = "40"><img src="4.jpg">
. 
</form> 
</body>
</html>
<?php
if ($status == 1) {
echo("<img src = 'http://cfile234.uf.daum.net/image/152622034C88B1DC682870'><br>");
}
if ($status == 2) {
echo("<img src = 'http://cfile223.uf.daum.net/image/162622034C88B1DC696BEC'><br>");
}
if ($status == 3) {
echo("<img src = 'http://cfile206.uf.daum.net/image/142622034C88B1DC6AA52F'><br>");
}
if ($status == 4) {
echo("<img src = 'http://cfile232.uf.daum.net/image/152622034C88B1DC6BFF47'><br>");
}
if ($status == 5) {
echo("<img src = 'http://cfile234.uf.daum.net/image/162622034C88B1DC6C0395'><br>");
}
?>
}}}
== 계층도랄까.. ==
[http://cfile231.uf.daum.net/image/166494114C8748111943D9 클릭하셈]
----
[2010PHP]


디비 연결 테스트

<?php
$link = mysql_connect('mysql5.hosting.paran.com', 'linflus', '****');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}else{
    echo("Connect Succesful.<br/>");
}

$db = mysql_select_db("linflus_db");
/*
$sql = "CREATE TABLE guest
    (no integer not null,
    name    char(10),
    contents    text(2000),
    password    char(4),
    status  integer,
    date    date)";

$result = mysql_query($sql);

if(!$result){
    die('Can not create table');
}else{
    echo($result);
}
*/

$sql = "INSERT INTO guest
    values(1, 'ksh', 'hello', '1234', 1)";
$result = mysql_query($sql);

$sql = "SELECT * FROM guest";
$result = mysql_query($sql);
$obj = mysql_fetch_object($result);

echo($obj->name);
?>

입출력 최종 완성 (9월 8일)

메인화면 ( index.php )

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>방명록</title>
<?php
include "dbconnect.php";
?>
<head>
<body>
<form method='post' action='process.php'>

이름&nbsp;&nbsp;<input type='text' name='input_name' maxlength='10' size='10'>&nbsp;&nbsp;&nbsp;&nbsp;
비밀번호&nbsp;&nbsp;<input type="password" name='input_pw'size='4' maxlength='4'>
<br>
<input type = "radio" name = "status" value = "1" size = "40" checked><img src="http://cfile234.uf.daum.net/image/152622034C88B1DC682870">
<input type = "radio" name = "status" value = "2" size = "40"><img src="http://cfile223.uf.daum.net/image/162622034C88B1DC696BEC">
<input type = "radio" name = "status" value = "3" size = "40"><img src="http://cfile206.uf.daum.net/image/142622034C88B1DC6AA52F">
<input type = "radio" name = "status" value = "4" size = "40"><img src="http://cfile232.uf.daum.net/image/152622034C88B1DC6BFF47">
<input type = "radio" name = "status" value = "5" size = "40"><img src="http://cfile234.uf.daum.net/image/162622034C88B1DC6C0395">
<br>
<textarea name='context' rows='4' cols='50'></textarea>
<br>
<input type='submit' value='전송'>

</form>

<?
include "print.php";
?>
</body>
</html>

데이터베이스에 연결 ( dbconnect.php )

<?php
$dbconn = mysql_connect("intra.zeropage.org", "csephp", "2010php");
$tableconn = mysql_select_db("csephp_db", $dbconn);
?>

쿼리를 만들때 시간을 저장하기 위해.. ( get_time.php )

<?php
$unix_ts=mktime();
$date=date('Y-m-d', $unix_ts);
?>

모든 처리는 여기서... ( process.php )

<?php
include "dbconnect.php";
/*********************
 *  쿼리를 
 *  만듭니다.
 *********************/
//이름 입력의 처리
if (strlen($_POST['input_name']) > 10 )	
{
	$posted_name = substr($_POST['input_name'],0,10);
}
else
{
	$posted_name = $_POST['input_name'];
}

//비번 입력의 처리
if (strlen($_POST['input_pw']) > 4 )	
{
	$posted_pw = substr($_POST['input_pw'],0,4);
}
else
{
	$posted_pw = $_POST['input_pw'];
}

//내용 입력의 처리
if (strlen($_POST['context']) > 2000 )	
{
	$posted_context = substr($_POST['context'],0,2000);
}
else
{
	$posted_context = $_POST['context'];
}
$posted_status = $_POST['status'];
include "get_time.php";
$query = "insert into guest (name, pw, status, contents, date) values ('$posted_name', '$posted_pw', '$posted_status', '$posted_context', '$date')";
/*********************
 *  쿼리를 전송
 *  합니다.
 *********************/
if(($posted_name!="")&&($posted_pw!="")&&($posted_pw!=""))
{
	$result = mysql_query($query, $dbconn);
}
header("location:index.php");
?>

입력을 받고, 출력(페이지 추가) ( print.php )

<?php
$query = "select * from guest ORDER BY no DESC";
$result = mysql_query($query, $dbconn);
$record_number = mysql_num_rows($result);
$scale = 10;//한 페이지당 글 수

//전체 페이지( $total_page ) 계산
if( $record_number % $scale == 0)
	$total_page = floor($record_number / $scale );
else
	$total_page = floor($record_number / $scale) + 1;

if(!$page)	$page = 1;

//페이지에 따라 $start 계산
$start = ($page -1) * $scale;


for( $i = $start; $i < $start + $scale && $i < $record_number; $i++){
	include "get_record.php";

	echo("<br>기본정보 : $name $no $pw $status $date <br>");
	echo("내      용 : $contents <br>");
	include "print_status.php";

}

for( $i=1; $i<=$total_page; $i++){
	if($page == $i){
		echo" <b>[$i]</b>";
	}
	else{
		echo"<a href='index.php?page=$i'>[$i]</a>";
	}
}
?>

출력을 위해 필요함 ( get_record.php )

<?
$name=mysql_result($result,$i,0);
$no=mysql_result($result,$i,1);
$pw=mysql_result($result,$i,2);
$contents=mysql_result($result,$i,3);
$status=mysql_result($result,$i,4);
$date=mysql_result($result,$i,5);
?>

오늘의 상태 (print_status.php)

<?php
if ($status == 1)	{
	echo("<img src = 'http://cfile234.uf.daum.net/image/152622034C88B1DC682870'><br>");
}
if ($status == 2)	{
	echo("<img src = 'http://cfile223.uf.daum.net/image/162622034C88B1DC696BEC'><br>");
}
if ($status == 3)	{
	echo("<img src = 'http://cfile206.uf.daum.net/image/142622034C88B1DC6AA52F'><br>");
}
if ($status == 4)	{
	echo("<img src = 'http://cfile232.uf.daum.net/image/152622034C88B1DC6BFF47'><br>");
}
if ($status == 5)	{
	echo("<img src = 'http://cfile234.uf.daum.net/image/162622034C88B1DC6C0395'><br>");
}
?>

계층도랄까..

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:11
Processing time 0.0594 sec