程序员的出路

alex.w的Blog

导航

php写入数据库

Posted on 2008-10-21 08:47  alex.w  阅读(685)  评论(0)    收藏  举报

<?
include_once 'Conn.php';
if($_POST['Submit']){
$sql = "insert into guestbook (ID,userName,title,content,lastdate) values  (NULL,'$_POST[userName]','$_POST[title]','$_POST[content]',now())";
echo $sql;
mysql_query($sql);
echo "成功";
}
?>
<form id="form1" name="form1" method="post" action="2.php">
  <label>
  <input name="userName" type="text" id="userName" />
  <br />
  </label>
  <label>
  <input name="title" type="text" id="title" />
  <br />
  </label>
  <label>
  <textarea name="content" id="content"></textarea>
  </label>
  <label>
  <input type="submit" name="Submit" value="提交" />
  </label>
</form>

 

Conn.php

<?
$conn=@mysql_connect("localhost","root","") or die ("连接错误");//数据库连接
mysql_select_db("newDB",$conn);//
mysql_query("SET NAMES gbk");
?>