Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

2010php/방명록만들기: Difference between revisions

From ZeroWiki
imported>linflus
No edit summary
imported>rlaace423
No edit summary
Line 1: Line 1:
== 디비 연결 테스트 ==
  <?php
  <?php
  $link = mysql_connect('mysql5.hosting.paran.com', 'linflus', '****');
  $link = mysql_connect('mysql5.hosting.paran.com', 'linflus', '****');
Line 35: Line 36:
   
   
  echo($obj->name);
  echo($obj->name);
?>
== 기본 화면 ==
<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>
== 글자 수 제한의 처리 ==
<?
//이름 입력의 처리
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'];
}
  ?>
  ?>
----
----
[[2010PHP]]
[[2010PHP]]



Revision as of 06:51, 16 August 2010

디비 연결 테스트

<?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);
?>

기본 화면

<html>
<head><title>방명록</title><head>
<body>
<form method='post' action='output.php'>

이름&nbsp;&nbsp;<input type='text' name='input_name' size='10'>&nbsp;&nbsp;&nbsp;&nbsp;
비밀번호&nbsp;&nbsp;<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>

글자 수 제한의 처리

<?
//이름 입력의 처리
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'];
}
?>

2010PHP