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