add.php 文件
<?php
/*
* Created on 2011-12-27
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
include("conn.php"); if(isset($_POST['submit']) && $_POST['submit']){
$sql = "insert into message (id,user,title.content,lastdate) values ('','$_POST[user]','$_POST[title]',$_POST[content].now())";
mysql_query($sql);
echo "<script language=\"javascript\">alert('添加成功');history.go(-1)</script>";
}
include("head.php");
?>
<script language="JavaScript">
function CheckPost()
{
if (myform.user.value=="")
{
alert("请填写用户名");
myform.user.focus();
return false;
}
if (myform.title.value.length<5)
{
alert("标题不能少于5个字符");
myform.title.focus();
return false;
}
if (myform.content.value=="")
{
alert("必须要填写留言内容");
myform.content.focus();
return false;
}
}</script>
<form action="add.php" method="post" name="myform" onsubmit="return CheckPost();">
用户:<input type="text" size="10" name="user" /><br>
标题:<input type="text" name="title" /><br/>
内容:<textarea name="content" cols="60" rows="9"></textarea><br/> <input type="submit" name="submit" value="发布留言"/></form>
conn.php 文件
<?php
/*
* Created on 2011-12-27
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
$conn = @ mysql_connect("localhost","root","") or die("数据库错误"); // 连接数据库
mysql_select_db("xuexi",$conn); //打开 xuexi 数据库
mysql_query("set names 'GBK'"); //使用GBK 中文编码; // 替换编码
function htmtocode($content){
$content = str_replace("\n","<br>",str_replace(" "," ",$content));
return $content;
}
?>
<?php
/*
* Created on 2011-12-27
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
include("conn.php"); if(isset($_POST['submit']) && $_POST['submit']){
$sql = "insert into message (id,user,title.content,lastdate) values ('','$_POST[user]','$_POST[title]',$_POST[content].now())";
mysql_query($sql);
echo "<script language=\"javascript\">alert('添加成功');history.go(-1)</script>";
}
include("head.php");
?>
<script language="JavaScript">
function CheckPost()
{
if (myform.user.value=="")
{
alert("请填写用户名");
myform.user.focus();
return false;
}
if (myform.title.value.length<5)
{
alert("标题不能少于5个字符");
myform.title.focus();
return false;
}
if (myform.content.value=="")
{
alert("必须要填写留言内容");
myform.content.focus();
return false;
}
}</script>
<form action="add.php" method="post" name="myform" onsubmit="return CheckPost();">
用户:<input type="text" size="10" name="user" /><br>
标题:<input type="text" name="title" /><br/>
内容:<textarea name="content" cols="60" rows="9"></textarea><br/> <input type="submit" name="submit" value="发布留言"/></form>
conn.php 文件
<?php
/*
* Created on 2011-12-27
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
$conn = @ mysql_connect("localhost","root","") or die("数据库错误"); // 连接数据库
mysql_select_db("xuexi",$conn); //打开 xuexi 数据库
mysql_query("set names 'GBK'"); //使用GBK 中文编码; // 替换编码
function htmtocode($content){
$content = str_replace("\n","<br>",str_replace(" "," ",$content));
return $content;
}
?>
解决方案 »
- 字符串加一问题 急啊
- php mysql扩展使用mysqli扩展查询结果的问题
- frame之间的传值?
- 使用PHPMailer以后需要更改php.ini文件吗
- php解析数据库中取出的html代码问题
- 问一下,这样写错哪儿了?为什么回提示这样的错?Parse error: parse error, unexpected T_FOREACH in
- 19本php精品图书下载的好网站
- 大家帮我看看这个是怎么实现的。。。。
- 新闻系统
- 调用session start()时报错:“Warning: open(/tmp\sess_2e735dde87e431bec9e6008c5bae795a, O_RDWR) failed: m (2) in ”是什么问题??
- php编程大学课表管理系统
- php 替换
看看都有什么
你的SQL语句有问题!首先id不能为空,第二 title和content之间应该是逗号,不是点!
$sql = "insert into message (id,user,title,content,lastdate) values ('11','$_POST[user]','$_POST[title]',$_POST[content],now())"
那个ID=11是我随便传的一个,现在你试试