디비 연결 테스트 ¶
<?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);
?>
기본 화면 (index.php) ¶
<html> <head><title>방명록</title><head> <body> <form method='post' action='output.php'> 이름 <input type='text' name='input_name' size='10'> 비밀번호 <input type="password" name='input_pw'size='4' maxlength='4'> <br> <textarea name='context' rows='4' cols='50'></textarea> <br> <input type='submit' value=' 전송 '> </form> </body> </html>
글자 수 제한의 처리 (process.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'];
}
?>
입력 받은 내용 출력 (output.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>");
?>
</body>
</html>
페이지 ¶
/* 필요한 거 */
//글 내용(순서대로) = $contents query로
//전체 글 수 = $total
//한 페이지 당 글 수 = $scale
//total 글 수를 받아온다. query로
$contents// mysql로 글 순서대로 받음
$total // $contents의 row 수
$scale = 10; // 페이지 당 글 수
$number = 1;
$start = 0;//처음
/*
if( $total % $scale == 0){//페이지 정하기
$page = floor($total / $scale);
}else{
$page = floor($total / $scale) + 1;
}
*/
/*각 페이지에 글 10개 씩 출력*/
/*페이지 번호 출력*/
for($number=1; $n_p < $total && $mode != 'new'; $number++){
//$p_p = $start - $scale ; // 이전 페이지는 시작 글에서 $scale을 뺀값부터
$n_p = $start + $scale*$number ; // 다음 페이지는 시작 글에서 $scale을 더한값부터
if ( ($total / $scale == $number) && ($total % $scale != 0) ) {//[2]페이지 이상
echo("<a href='$PHP_SELF?start=$n_p'>[$number+1]</a> ");
}
if ( ($total == 10 ) {//[1]페이지
echo("<a href='$PHP_SELF?start=$n_p'>[1]</a></center> ");
}
오늘의 상태 ¶
나머지 부분은 생략
기본화면에 첨부하면 되므로..ㅋ
기본화면에 첨부하면 되므로..ㅋ
<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>
색 바꾸기 ¶
<?
echo("<h1>배경색을 바꾸자</h1><br>");
echo("
<form method='post' action='$PHP_SELF'>
R <input type='text' maxlength='3' name='setr' size='3'><br>
G <input type='text' maxlength='3' name='setg' size='3'><br>
B <input type='text' maxlength='3' name='setb' size='3'><br>
혹은 그냥 색 이름 입력(영어로) <input type='text' name='clrname'><br>
<input type='submit' value='전송'>
");
if($_POST['clrname'] != NULL)
{
echo('<body bgcolor='.$_POST['clrname'].'>');
}
else
{
// 배경 색의 처리
$hexr=dechex($_POST['setr']);
$hexg=dechex($_POST['setg']);
$hexb=dechex($_POST['setb']);
echo('<body bgcolor='.$hexr.$hexg.$hexb.'>');
}
// 글자가 보이기 위해 글자 색의 처리
$txtr=dechex(255-$_POST['setr']);
$txtg=dechex(255-$_POST['setg']);
$txtb=dechex(255-$_POST['setb']);
?>










