<?php
include('conn.php');if($_POST['username']){$sql = "insert into easy values('$_POST[username]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
}
?><div align = "center">
<table width=500 border="0" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
//中间是表单样式,略去
<?php
$SQL="SELECT * FROM easy order by posttime desc ";
$query=mysql_query($SQL);
while($row=mysql_fetch_array($query)){
?> <tr bgcolor="#eff3ff">
<td>标题:<?=$row[title]?></td>
<td>用户:<?=$row[username]?></td>
<td> <?= $row[posttime]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?= ($row[content])?></td>
</tr><?php
}
?>
</table>
include('conn.php');
if($_POST['username']) //我想是不是这里有问题,但只是刷新页面,并没有传递数据呀
<?php
include('conn.php');if($_POST['username']){$sql = "insert into easy values('$_POST[username]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
}
?><html>
<script language = "javascript">
function checkMessage()
{
if(msgform.username.value == "")
{
alert("用户名不能为空!");
msgform.username.focus();
return fause;
} if(msgform.title.value =="")
{
alert("标题不能为空!");
msgform.title.focus();
return fause;
}
if(msgform.content.value =="")
{
alert("留言内容不能为空!");
msgform.content.focus();
return fause;
}
return true;
}
</script>
<body bgcolor = "#FFFFFF" text = "#000000">
<h1 align = center><font color = blue>给我留言</font></h1>
<form name = "msgform" method = "post" action = "input.php" enctype = "multipart/form-data" onsubmit = "return checkMessage()">
<table width = "64%" border = "0" cellspacing = "1" cellpadding = "3" bgcolor = "#66CCFF" align = "center">
<tr>
<td width = "48%">用 户:
<input type = "txet" name = "username">
</td></tr><tr>
<td colspan = "2">标 题:
<input type = "text" name = "title" size = "60" maxlength = "50">
</td>
</tr>
<tr>
<td colspan = "2">
<textarea name = "content" rows = "10" cols = "100"></textarea>
</td>
</tr>
<tr>
<td>
<div align = "right">
<input type = "submit" name = "sub" value = "提交">
</div>
</td>
<td>
<input type = "reset" name = "Rewrite" value = "重写">
</td>
</tr>
</table><div align = "center">
<table width=500 border="0" cellpadding="5" cellspacing="1" bgcolor="#add3ef"><?php
$SQL="SELECT * FROM easy order by posttime desc ";
$query=mysql_query($SQL);
while($row=mysql_fetch_array($query)){
?> <tr bgcolor="#eff3ff">
<td>标题:<?=$row[title]?></td>
<td>用户:<?=$row[username]?></td>
<td> <?= $row[posttime]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?= ($row[content])?></td>
</tr><?php
}
?>
</table>
</div>
</form>
</body>
</html>
include('conn.php');
if($_POST['username']){
$sql = "insert into easy values('$_POST[username]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
//意思就是在这之后做一个跳转处理或者其他去掉提交动作处理,比如
echo '<meta http-equiv="refresh" content="1;url=index.php">'
}
?>
提交成功后,跳转一下页面就可以了if($_POST['username']){
$sql = "insert into easy values('$_POST[username]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo echo "<script language=\"javascript\">alert('提交成功');location.href='add.php';</script>"; }