你好阿,我是php的初学者,在制作一个php的小留言板上出现了一点问题:执行的sql操作好像写不进去mysql?但不知道到底是程序,还是软件配置或那里出了问题?请教一下各位了! 程序如下:add.php文件<?php
/*
 * 在 2009-12-31的时候新建立!
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 *
 *             发表页面  留言提交到数据库的文件
 */
 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);
echo "您的发布成功~";
 }?>
<!--提交到当前页面哦~ action为add.php-->
<!--整个form表单的提交方法为post,即下面的所有表单元素都是以post为提交的方法-->  <form action="add.php" method="post" >
  用户:<input type="text" name="user" size="10" /><br>
  标题:<input type="title" name="title" /><br>
内容:<textarea name="content" ></textarea><br><br>
<input type="submit" name="submit" value="提交您的内容"/>
  </form>conn.php文件<?php
/*
 * 在 2009-12-31的时候新建立!
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 *
 *                   链接数据库文件
 */ $conn=@ mysql_connect("localhost","root","111111pzm") or die("数据库链接有错误");
 mysql_select_db("bbs",$conn);
 mysql_query("set names 'GBK'");
?>list.php文件<?php
/*
 * 在 2009-12-31的时候新建立!
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 *
 *
 */
 include("conn.php");
?>   <table width="500" cellspacing="1" cellpadding="5" border="0" align="center" bgcolor="#99CC66">
  <?
  $sql="select * from message";
  $query=mysql_query($sql);
  while ($row=mysql_fetch_array($query)) {  //这个函数每一次返回一条记录,
                                                                      //每条记录的若干个属性构成一个数组给row
  ?>
  <tr bgcolor="#FF3366">
  <td>用户:<?=$row[user]?> 标题:<?=$row[title]?></td>
  </tr>
  <tr bgcolor="#FFFFFF">
  <td>内容:<?=$row[content]?></td>
  </tr>
  <?
  }
  ?>
  </table>谢谢帮忙!

解决方案 »

  1.   

    $sql="insert into message(id,user,title,content,lastdate) " .
                 "values('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
    这句改成这样试试$sql="insert into message(id,user,title,content,lastdate) " .
                 "values(null,'$_POST[user]','$_POST[title]','$_POST[content]',now())";
      

  2.   

    你先把你的SQL语句直接在数据库里运行看看
      

  3.   


    $sql="insert into message(id,user,title,content,lastdate) " .
                 "values(null,'$_POST[user]','$_POST[title]','$_POST[content]',now())";把每个$_POST[]变量改成${_POST[]}就好了,是不是sql语句不能识别以$号开始的变量呢?,加上{}就是区别变量???