PHP China | 中国开源之路 's Archiver

msubsdtt 发表于 2008-11-18 22:27

简单的留言板,数据写不到数据库??????//

我写的代码,请高手指点一下,谢谢了.
/*
<?php
include ("conn.php");
if($_post['submit'])
{
     echo  $sql = "insert into message (id,user,title,content,lastdate)" .
    "values ('','$_post[user]','$_post[title]','$_post[content]',now())";
    mysql_query($sql) or die("数据库链接错误");
    echo "发表成功";
  // }else
   // {
   // echo "errors";
    }
?>
<form action="add.php" method="post" >
用户: <input type="text" size="10" name="user"/><br>
标题: <input type="text" name="title"/><br>
内容: <textarea name="content"></textarea><br>
<input type="submit" name="submit" value="发布留言"/>

</form>
*/

[[i] 本帖最后由 msubsdtt 于 2008-11-20 23:30 编辑 [/i]]

于安 发表于 2008-11-18 22:31

数组要用{$array[value]}

在SQL中.

yafeikf 发表于 2008-11-18 22:48

回复 2# 于安 的帖子

LS正解

utfqvfhpyygy 发表于 2008-11-18 23:10

干嘛不用中间变量?看起来好看多了

msubsdtt 发表于 2008-11-18 23:26

[quote]原帖由 [i]于安[/i] 于 2008-11-18 22:31 发表 [url=http://bbs.phpchina.com/redirect.php?goto=findpost&pid=730724&ptid=91790][img]http://bbs.phpchina.com/images/common/back.gif[/img][/url]
数组要用{$array[value]}

在SQL中. [/quote]



我是新手,请说的详细点.

koin 发表于 2008-11-18 23:42

我估计是名字是中文,编码的事

phper0513 发表于 2008-11-19 14:02

注意$_POST 要大写! 我在本机测试通过!mysql 字符是gb2312

<?php
include ("conn.php");
if($_POST['submit'])
{
    $sql = "insert into message (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
    mysql_query($sql) or die("数据库链接错误");
    echo "发表成功";
   }else
    {
    echo "errors";
    }
?>

<form action="add.php" method="post" >
用户: <input type="text" size="10" name="user"/><br>
标题: <input type="text" name="title"/><br>
内容: <textarea name="content"></textarea><br>
<input type="submit" name="submit" value="发布留言"/>
</form>

[[i] 本帖最后由 phper0513 于 2008-11-19 14:05 编辑 [/i]]

cnqn 发表于 2008-11-19 14:04

是的,$_POST一定要是大写,否则不行的

gehouse 发表于 2008-11-19 14:11

复杂变量放在 双引号中要加大{},不要以为pHP编译器是神仙。

bless 发表于 2008-11-19 14:24

id不应该是''

phper0513 发表于 2008-11-19 15:04

[quote]原帖由 [i]bless[/i] 于 2008-11-19 14:24 发表 [url=http://bbs.phpchina.com/redirect.php?goto=findpost&pid=732630&ptid=91790][img]http://bbs.phpchina.com/images/common/back.gif[/img][/url]
id不应该是'' [/quote]
mysql 中 id设为auto_increment 没有影响

bless 发表于 2008-11-19 16:23

添加''即是空文本不可向id(int)添加,故添加不了

msubsdtt 发表于 2008-11-20 23:29

[quote]原帖由 [i]cnqn[/i] 于 2008-11-19 14:04 发表 [url=http://bbs.phpchina.com/redirect.php?goto=findpost&pid=732556&ptid=91790][img]http://bbs.phpchina.com/images/common/back.gif[/img][/url]
是的,$_POST一定要是大写,否则不行的 [/quote]


谢谢了,我是新手,忽略了这一点.

msubsdtt 发表于 2008-11-20 23:29

[quote]原帖由 [i]phper0513[/i] 于 2008-11-19 14:02 发表 [url=http://bbs.phpchina.com/redirect.php?goto=findpost&pid=732544&ptid=91790][img]http://bbs.phpchina.com/images/common/back.gif[/img][/url]
注意$_POST 要大写! 我在本机测试通过!mysql 字符是gb2312

[/quote]

我是新手,忽略了大小写问题.

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.