간단한 게시판

2799 단어 메모판
<?php
include "02.php";
$sql="select count(*) from liu";
$result=mysql_query($sql,$conn);
$row=mysql_fetch_row($result);
echo $row[0];
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title> </title>
<script language="javascript">
function test(){
	if(myform.title.value==""){
		alert(" !");
		return false;
	}else{
		$sum=myform.title.value.length;
		if($sum<5 || $sum>20){
			alert(" 5-20 ");
			return false;
		}
	}
	if(myform.name.value==""){
		alert(" !");
		return false;
	}else{
		$sum=myform.name.value.length;
		if($sum<2 || $sum>10){
			alert(" 2-10 ");
			return false;
		}
	}
	if(myform.content.value==""){
		alert(" !!");
		return false;
	}else{
		$sum=myform.content.value.length;
		if($sum<10){
			alert(" 10");
			return false;
		}
	}
	return true;
}
</script>
</head>
<body>
<form action="01.php" method="post" name="myform" onsubmit="return test();">
<table width="500" height="30" cellpadding=0 cellspacing="0" border="0">
<h2> </h2>
<tr>
<td align="right"> :</td>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td align="right"> :</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td align="right"> :</td>
<td>
<textarea cols="40" rows="5" name="content"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
include "02.php";
$title=magic($_POST['title']);
$name=magic($_POST['name']);
$content=magic($_POST['content']);
$time=date("Y-m-d H:i:s");
function magic($str){
	$str=trim($str);
	if(!get_magic_quotes_gpc()){
		$str=addslashes($str);
	}
	return htmlspecialchars($str);
}
echo $title.$name.$content;
$sql="insert into liu(title,name,content,time) values('$title','$name','$content','$time')";
$isok=mysql_query($sql,$conn);
if($isok){
	echo " ";
}else{
	echo " ";
}
<?php
$conn=mysql_connect('localhost','root','');
if(!$conn){
	echo " ";
}
$sql="use test";
mysql_query($sql,$conn);
$sql="set names utf8";
mysql_query($sql,$conn);

좋은 웹페이지 즐겨찾기