javascript 自定义函数 执行
<?php/*
* Created on 2013-7-28
*
*/
include("conn.php");//非文本type用''或""
//判断是否提交
if(!empty($_POST['sbmt'])){
echo $sql="insert into message (id,username,title,content,lastdate) values('','$_POST[username]','$_POST[title]','$_POST[content]',now())";
$result = mysql_query($sql);
if($result){
echo "<script type='text/javascript'>alert('留言成功!');</script>";
}else{
echo "<script type='text/javascript'>alert('留言失败!');</script>";
}
echo "<script type='text/javascript'>location.href='add.php'</script>";
}
include("head.php");
?>
<script language='javascript'>
function CheckPost(){
if(document.myform.username.value==""){
alter("please fill into username");
myform.username.focus();
return false;
}
if(myform.title.value.length<5){
alter("title must be great to 5 characters");
myform.title.focus();
return false;
}
}
</script>
<form action="add.php" ,name="myform" method="post" onsubmit="return CheckPost();">
用户名:<input type="text" name="username" /><br/>
标 题:<input type="text" name="title" /><br/>
留言内容:<textarea name="content" cols="60" rows="2"></textarea><br/>
<input type="submit" name="sbmt" value="留言" /><br/>
</form>