<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>サンプル：掲示板</title></head>
<body>
<form method="POST" action="<?php echo $PHP_SELF; ?>" name="keijiban"> 
<table border="0" bgcolor="green" cellpadding="2" cellspacing="2">
<tr>
<th bgcolor="white">お名前</th><td bgcolor="white"><input type="text" name="name" size="30"></td>
</tr>
<tr>
<th bgcolor="white">Eメール</th><td bgcolor="white"><input type="text" name="email" size="30"></td>
</tr>
<tr>
<th bgcolor="white">題名</th><td bgcolor="white"><input type="text" name="subject" size="30"></td>
</tr>
<tr>
<th bgcolor="white">コメント</th><td bgcolor="white"><textarea rows="3" cols="30"  name="comment"></textarea></td>
</tr>
<tr>
<td colspan="2" bgcolor="white" align="center"><input type="submit" name="submit" value="送信">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="regist">&nbsp;<input type="reset" name="reset" value="リセット"></td>
</tr>
</table>
</form>
<?php
//タグを取り除く
$name=strip_tags($name);
$email=strip_tags($email);
$subject=strip_tags($subject);
$comment=strip_tags($comment);
$date=date("Y/m/d H:i:s");//日付の取得
//データベース接続
$con = pg_connect("host=localhost  dbname=knodb user=k-serv_2");
  if (!$con){
    print "DBへの接続に失敗しました!\n";
    exit;
    }
//エンコード
    $name=mb_convert_encoding($name,"EUC","SJIS");
    $email=mb_convert_encoding($email,"EUC","SJIS");
    $subject=mb_convert_encoding($subject,"EUC","SJIS");
    $comment=mb_convert_encoding($comment,"EUC","SJIS");
//データベースへインサート
pg_query($con, "insert into keijiban(name,email,subject,comment,date) values ('$name','$email','$subject','$comment','$date')");
//データベースからセレクト
$data_view=pg_query($con,"select * from keijiban order by num desc");
//echo $data_view;
$row=pg_num_rows($data_view);
//echo $row;
for($i=1; $i <= $row; $i++){
$data_array=pg_fetch_array($data_view,$i-1,PGSQL_ASSOC);
//エンコード
    $name=mb_convert_encoding($data_array[name],"SJIS","EUC");
    $email=mb_convert_encoding($data_array[email],"SJIS","EUC");
    $subject=mb_convert_encoding($data_array[subject],"SJIS","EUC");
    $comment=mb_convert_encoding($data_array[comment],"SJIS","EUC");
echo "[★" . $data_array[num] . "]";
echo "[名前：" . $name . "]";
echo "[日付：" . $data_array[date] . "]";
echo "[メールアドレス：" . $email . "]";
echo "<br>";
echo "[題名：" . $subject . "]";
echo "<br>";
echo "[コメント：" . $comment . "]";
echo "<hr>";
}
?>
</body>
</html>