U E D R , A S I H C RSS

데블스캠프2013/둘째날/API

index.php

<html>
<head>
	<title>***의 홈페이지</title>
	<meta charset="utf-8">
</head>
<body>
	<form method="post"
		action="write.php">
		이름 <input name="name" size="10">
		내용 <input name="text" size="40">
		<input type="submit">
	</form>
	<table border="1">
		<thead>
			<tr>
				<th>번호</th>
				<th>이름</th>
				<th>내용</th>
				<th>IP</th>
			</tr>
		</thead>
		<tbody>
		<?
			mysql_connect('127.0.0.1', 'root', 'apmsetup');
			mysql_select_db('devilscamp');
			mysql_query('set names utf8');
			
			$q = mysql_query("select id,name,text,ip from board order by id desc");
			
			while ($data = mysql_fetch_row($q)) {
				$id = $data[0];
				$name = $data[1];
				$text = $data[2];
				$ip = $data[3];
				echo "<tr><td>$id</td><td>$name</td><td>$text</td><td><a href='http://$ip'>$ip</a></td></tr>";
			}

			mysql_close();
		?>
		</tbody>
	</table>
</body>
</html>

write.php

<?
	mysql_connect('127.0.0.1', 'root', 'apmsetup');
	mysql_select_db('devilscamp');
	mysql_query('set names utf8');
	
	if (!trim($_POST['name']) || !trim($_POST['text'])) {
		echo '<script>alert("내용이 없습니다."); location.href="index.php";</script>';
		return;
	}
	
	mysql_query("insert into board(name,text,ip) values ('{$_POST['name']}', '{$_POST['text']}', '{$_SERVER['REMOTE_ADDR']}')");

	mysql_close();
	
	echo '<script>alert("등록되었습니다."); location.href="index.php";</script>';
?>
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:16
Processing time 0.0134 sec