+ -
当前位置:首页 → 问答吧 → 能连接数据库,但就是不能传值。求解。谢谢

能连接数据库,但就是不能传值。求解。谢谢

时间:2010-10-12

来源:互联网

     刚在新手区发过,没能够解决,希望大家帮助下。
conn.php文件
                        <?php
/*
 * Created on 2010-10-12
 */
 $conn=@ mysql_connect("localhost","root","")or die("数据库链接超时");

 mysql_select_db("bbs",$conn);

 mysql_query("set names 'gbk'");

 print (@mysql_ping())?'connected':'no connect';
?>

add.php文件
                       <?php
/*
 * Created on 2010-10-12
 */
 include("conn.php");

 if($_POST['sumbit']){

  $sql="insert into message (id,user ,title,content,lastdate)".

  "('','$_post[user]','$_post[title]','$_post[content]',now())";

 mysql_query($sql);

 echo "发布成功" ;
 }

?>
<form action="add.php" method="post">

用 户:<input type="text"  size="10" name="user" /><br>

标 题:<input type="type" size="50" name="title" /><br>

内  容:<textarea name="content" /></textarea><br>

<input type="submit" name="submit" value="提交" /><br>

</form>


 总是已提交就变空白了

作者: 我已是痴人   发布时间: 2010-10-12

$_post[user]','$_post[title]','$_post[content]',now())";


POST 要大写

作者: mare   发布时间: 2010-10-12

$sql="insert into message (id,user ,title,content,lastdate)".


user ,     后面有空格

作者: mare   发布时间: 2010-10-12

  $sql="insert into message (id,user ,title,content,lastdate) VALUES   ('','$_post[user]','$_post[title]','$_post[content]',now())";

中间少了 VALUES  

作者: mare   发布时间: 2010-10-12

  $sql="INSERT INTO  `message`  SET  `id`='',`user`=$_POST['user'],`title`=$_POST['user'],`content`=$_POST['content'],`lastdate`=now()";

我比较喜欢这中写法,比较直观

作者: mare   发布时间: 2010-10-12

感谢大哥你了啊。我去试试

作者: 我已是痴人   发布时间: 2010-10-12

还是不行啊

作者: 我已是痴人   发布时间: 2010-10-12

                       <?php
/*
* Created on 2010-10-12
*
  *include("conn.php");
*/

if($_POST['sumbit']){

/*    注释掉,看看有没有结果。 有就说明是sql问题,  $sql="insert into message (id,user ,title,content,lastdate)".

  "('','$_post[user]','$_post[title]','$_post[content]',now())";

mysql_query($sql);

*/

echo "发布成功" ;
}

?>
<form action="add.php" method="post">

用 户:<input type="text"  size="10" name="user" /><br>

标 题:<input type="type" size="50" name="title" /><br>

内  容:<textarea name="content" /></textarea><br>

<input type="submit" name="submit" value="提交" /><br>

</form>

作者: mare   发布时间: 2010-10-12

热门下载

更多