2012年2月9日 星期四

php留言板code

<html>
<head>
<title>留言板</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" >
<style>
h3 {
color:#FF8000;
font-family:Verdana;
}
p {
color:blue;
color:#844200;
}
div { 
color:#7b7b7b;
font-size:10pt;
}
hr {
border-top:1px solid #FF8000;
}
</style>
</head>
<body>
<form name="f1" action="index.php" method="post" >
Name: <input type="text" name="uid" value="" /> <br/>
Location: <input type="text" name="userhome" value="" /><br/>
Title: <input type="text" name="title" value=""  /> <br/>
Content: <br/><textarea name="content" rows="5" cols="35" ></textarea><br/>
<input type ="submit" value="send" />
<input type ="reset" value="clear" />
<a href="index.php">refresh</a>
</form>
<hr/>


<?php
@$username=(string)$_REQUEST["uid"];
@$title=$_REQUEST["title"];
@$msg=$_REQUEST["content"];
@$currentdate = date("Y-m-d h:i:A");
@$userhome=$_REQUEST["userhome"];


 $link = mysql_pconnect("localhost", "root", "");
  mysql_query("SET NAMES 'utf8'");
  mysql_select_db("test") or die("插不進去");
  
  if($username != null) {
  $query = "INSERT INTO message (title,content,username,currentdate,userhome) 
  VALUES ('$title','$msg','$username','$currentdate','$userhome')";
 mysql_query($query) or die("error" . mysql_error( ));
  }
  
$query  = "SELECT * FROM message order by mid desc";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{  
    echo "<h3 class='title'>{$row['title']} </h3> ";
echo "<p>{$row['content']}</p>";
echo "<div>我是:{$row['username']} <br/>";
echo "留言於:{$row['currentdate']}, from  {$row['userhome']} <br/></div>";
echo "<hr/>";

?>


</body>
</html>