<?php
$conn=@mysql_connect("localhost","root","") or die("数据库连接错误");
mysql_select_db("test",$conn);mysql_query("set names 'GBK'");
?>
<?php
include("conn.php");
if($_POST["sumbit"])
{
$sql="insert into message(id,user,title,content) value('','$_post[user]','$_POST[title]','$_POST[content]')";
mysql_query($sql,$conn);
}
echo"留言成功";
?><form action="addly.php" method="post">
用户名:<input type="text" name="user"><br/><br/>
标题: <input type="text" name="title"><br/><br/>
留言内容:
<textarea name="content" rows="10" cols="50"></textarea><br/><br/>
<input type="submit" name="sumbit" value="提交内容">
</form>
为什么提交后内容无法加入数据库
$conn=@mysql_connect("localhost","root","") or die("数据库连接错误");
mysql_select_db("test",$conn);mysql_query("set names 'GBK'");
?>
<?php
include("conn.php");
if($_POST["sumbit"])
{
$sql="insert into message(id,user,title,content) value('','$_post[user]','$_POST[title]','$_POST[content]')";
mysql_query($sql,$conn);
}
echo"留言成功";
?><form action="addly.php" method="post">
用户名:<input type="text" name="user"><br/><br/>
标题: <input type="text" name="title"><br/><br/>
留言内容:
<textarea name="content" rows="10" cols="50"></textarea><br/><br/>
<input type="submit" name="sumbit" value="提交内容">
</form>
为什么提交后内容无法加入数据库
另外打开数据库后,里面无内容!
这天SQL语句的value-》values;
另外values前面的括号字段要加小引号``
这样 message(`id`,`user`,`title`,`content`) 试一试;
几个地方改进一下基本就可以了。
1.Notice: Undefined index: sumbit in E:\wamp\www\addly.php on line 4
if($_POST['submit'])改成if ( !empty($_POST['submit'])。2.$sql="insert into message(user,title,content) value('$_post[user]','$_POST[title]','$_POST[content]')";3.后面再加这么一句
if ( mysql_query($sql) )
{
echo "留言成功";
}
************************************************
淄博本地信息网 http://www.zbinfos.com
$title=trim($_POST['title']);
$user=trim($_POST['user']);
$tel=trim($_POST['tel']);
$fax=trim($_POST['fax']);
$email=trim($_POST['email']);
$content=trim($_POST['content']);
$date=time();if($_POST['submit']){
mysql_query("INSERT INTO user_info (id,title,user,tel,fax,email,content,date)
VALUES ('', '$title', '$user','$tel','$fax','$email','$content','$date')");echo"<script> alert('Submit success!');history.go(-2);</script>";
}