conn.php代码
<?php @mysql_connect("localhost:3306","root","")or die("mysql连接失败"); @mysql_select_db("php100")or die("db连接失败"); mysql_query("set names 'gbk'");?>
add.php代码
<?php include("conn.php");if(!empty($_POST['sub'])){ $title=$_POST['title']; $con=$_POST['con']; $sql="insert into news(id,title,dates,contents)values(null,'$title',now(),'$con')"; mysql_query($sql); echo "插入成功";}?>
<form action="add.php" method="post">标题<input type="text" name="title"><br>内容<textarea rows="5" cols="50" name="con"></textarea><br><input type="submit" name="sub" value="发表"></form>
拉风的咖菲猫