U E D R , A S I H C RSS

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.0134 sec