主要问题是可以写留言,可以提交,但是不能写如数据库?

解决方案 »

  1.   

    你自己写的程序吗?检测下 POST 数据有没有正常提交。print_r($_POST);然后检测有没有正常连接数据库、写入数据库。吧写入数据库的SQL语句echo下,看看正常不。
      

  2.   

    先把你代码贴出来,别人才能帮你。
    留言无非也就是把post得到的东西inerst into到相应的字段。很有可能是你代码上的小问题。
      

  3.   

     <script language="JavaScript">
    <!--
    function check_form(form1){
    if(form1.user_name.value==""){
    alert("名称不能为空!");form1.user_name.focus();return false;
    }
    if(form1.title.value==""){
    alert("标题不能为空!");form1.title.focus();return false;
    }
    if(form1.content.value=="") {
    alert("内容不能为空!");form1.content.focus();return false;
    }
    if(form1.checkcode.value==""){
    alert("验证码不能为空!");form1.checkcode.focus();return false;
    }
    if(form1.checkcode.value!=num){
    alert("您输入的验证码不正确,重新输入!");form1.checkcode.focus();return false;
    }
    }
    //-->
    </script>
    <table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><?php include("header.html");?></td>
      </tr>
      <tr>
        <td valign="top"><table width="950" align="center"cellpadding="0" cellspacing="0" style="border:0;align:center;">
            <!-- 显示文章内容 -->
            <tr>
              <td width="949" align="right"  bgcolor="#FFFFFF"><table width="950" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
                  <tr>
                    <td><table width="100%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
                  <tr>
                    <td height="44" background="images/a_11.jpg">&nbsp;</td>
                  </tr></table>
                      <table width="761" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FEFEFE" bgcolor="#FFFFFF">
                        <form action="note_check.php"  method="post" name="form1" id="form1">
                          <tr>
                            <td width="761" height="40" bgcolor="#FFFFFF" style="BACKGROUND-IMAGE: url(image/bar_pink.gif); COLOR: #000000; BACKGROUND-COLOR: #FFFFFF"><marquee scrollamount="2" scrolldelay="100">
                              留下您珍贵的一笔是对本站最大的帮助!感谢您留言!
                              </marquee>
                              <hr color="#8AA925" size="2" style="width:750px; "></td>
                          </tr>
                           <tr>
                            <td align="center" bgcolor="#F9F8EF"><table width="749" border="0" align="center" cellpadding="0"  cellspacing="0"  style="BORDER-COLLAPSE: collapse">
                                <tr>            
                                  <td width="749" height="57" background="images/a_03.jpg">&nbsp;&nbsp;</td>
                                </tr>
                                <tr>
                                  <td height="36" colspan="3" align="left" background="images/a_05.jpg" bgcolor="#F9F8EF" scope="col">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓&nbsp;&nbsp;名:
                                    <input  name="user_name" id="user_name" value=" 匿名" maxlength="64" type="text" />
                                      <span 
                style="COLOR: #ff0000">*</span></td>
                                </tr>
                                <tr>
                                  <td height="36" colspan="3" align="left" background="images/a_05.jpg" bgcolor="#F9F8EF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;标 题:
                                    <input maxlength="64" size="30" name="title"  type="text"/>
                                      <span style="COLOR: #ff0000">*</span></td>
                                </tr>
                             <tr>
                                  <td height="126" colspan="3" align="left" background="images/a_05.jpg" bgcolor="#F9F8EF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;内&nbsp;&nbsp;容:
                                    <textarea name="content" cols="60" rows="8" id="content" style="background:url(./images/mrbccd.gif)"></textarea>
                                      <span style="COLOR: #ff0000">*</span></td>
                                </tr>   
                                <tr>
                                  <td height="40" colspan="3" align="left" background="images/a_05.jpg" bgcolor="#F9F8EF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;您现在的心情:
      

  4.   

    <input name="mood" type="radio" value="&lt;img src='images/face/1.gif'&gt;" checked="checked" />
                                      <img src="images/face/1.gif" width="20" height="20" />&nbsp;
                                      <input name="mood" type="radio" value="&lt;img src='images/face/2.gif'&gt;" />
                                      <img src="images/face/2.gif" width="20" height="20" />&nbsp;
                                      <input name="mood" type="radio" value="&lt;img src='images/face/3.gif'&gt;" />
                                      <img src="images/face/3.gif" width="20" height="20" />&nbsp;
                                      <input name="mood" type="radio" value="&lt;img src='images/face/4.gif'&gt;" />
                                      <img src="images/face/4.gif" width="20" height="20" />&nbsp;
                                      <input name="mood" type="radio" value="&lt;img src='images/face/5.gif'&gt;" />
                                      <img src="images/face/5.gif" width="20" height="20" />&nbsp;
                                      <input name="mood" type="radio" value="&lt;img src='images/face/6.gif'&gt;" />
                                      <img src="images/face/6.gif" width="20" height="20" />&nbsp;
                                      <input name="mood" type="radio" value="&lt;img src='images/face/7.gif'&gt;" />
                                      <img src="images/face/7.gif" width="20" height="20" />&nbsp;
                                      <input name="mood" type="radio" value="&lt;img src='images/face/8.gif'&gt;" />
                                      <img src="images/face/8.gif" width="20" height="20" />&nbsp;
                                      <input name="mood" type="radio" value="&lt;img src='images/face/9.gif'&gt;" />
                                      <img src="images/face/9.gif" width="38" height="26" />&nbsp;
                                      <input name="mood" type="radio" value="&lt;img src='images/face/10.gif'&gt;" />
                                      <img src="images/face/10.gif" width="25" height="20" />&nbsp;</td>
                                </tr>
                                <tr>
                                  <td height="40" colspan="3" align="left" background="images/a_05.jpg" bgcolor="#F9F8EF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;验证码:
                                    <input name="checkcode" type="text" id="checkcode" size="12" />
                                      <span class="STYLE11">
                                      <input type="hidden" name="createcheckcode" value="" />
                                      <script language="JavaScript" type="text/javascript">
    var num1=Math.round(Math.random()*10000000);
    var num=num1.toString().substr(0,4);
    document.form1.createcheckcode.value=num;
    document.write("<img name=codeimg4 src='checks.php?num="+num+"'>");
      </script>
                                      </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/whisper.gif" width="16" height="16" /> &nbsp;
                                      <input type="checkbox" name="checkbox" value="1" />
                                    给版主的悄悄话</td>
                                </tr>
                                <tr>
                                  <td height="35" background="images/a_07.jpg">&nbsp;&nbsp;</td>
                                </tr>
                            </table></td>
                          </tr>
                          <tr>
                            <td align="center" bgcolor="#F9F8EF"><table width="754" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td height="58" background="images/a_08.jpg"></td>
                                </tr>
                                <tr>
                                  <td height="76" align="center" background="images/a_09.jpg"><table width="534" height="100" border="0"   cellpadding="0" cellspacing="0">
                                      <tr style="VERTICAL-ALIGN: bottom">
                                        <td width="132" 
                    style="BORDER-RIGHT: #D9D2B6 1px solid; BORDER-TOP: #D9D2B6 1px solid; BORDER-LEFT: #D9D2B6 1px solid; BORDER-BOTTOM: #D9D2B6 1px solid"><input  type="radio"  checked="checked" value="01" name="head" />
                                            <img  src="images/face/pic/01.gif" width="90" height="90" /></td>
                                        <td width="134" 
                    style="BORDER-RIGHT: #D9D2B6 1px solid; BORDER-TOP: #D9D2B6 1px solid; BORDER-LEFT: #D9D2B6 1px solid; BORDER-BOTTOM: #D9D2B6 1px solid"><input  type="radio" value="02" name="head" />
                                            <img   src="images/face/pic/02.gif" width="90" height="90" /></td>
                                        <td width="134" 
                    style="BORDER-RIGHT: #D9D2B6 1px solid; BORDER-TOP: #D9D2B6 1px solid; BORDER-LEFT: #D9D2B6 1px solid; BORDER-BOTTOM: #D9D2B6 1px solid"><input  type="radio" value="03" name="head" />
                                            <img  src="images/face/pic/03.gif" width="90" height="90" /></td>
                                        <td width="134"  style="BORDER-RIGHT: #D9D2B6 1px solid; BORDER-TOP: #D9D2B6 1px solid; BORDER-LEFT: #D9D2B6 1px solid; BORDER-BOTTOM: #D9D2B6 1px solid"><input type="radio" value="04" name="head" />
                                          <img  src="images/face/pic/04.gif" width="90" height="90"></td>
                                      </tr>
                                  </table></td>
                                </tr>
                                <tr>
                                  <td height="20" background="images/a_10.jpg">&nbsp;</td>
                                </tr>
                              </table>
                                <table width="734" border="0" align="center" cellpadding="0" cellspacing="0">
                                  <tr>
                                    <td width="703" height="40" align="center"><input name="submit" type="submit" class="btn1" id="submit" value="签写留言" onclick="return check_form(form1);"/>
                                      &nbsp;&nbsp;
                                      <input name="reset" type="reset" class="btn1" value="清除留言" /></td>
                                  </tr>
                              </table></td>
                          </tr>
                        </form>
                      </table></td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
      </tr>
      
    </table>
      

  5.   

    后台的程序:<?php
    error_reporting(E_ALL ^ E_NOTICE); 
    require("global_manage.php");
    //检索数据信息
    $sql = "select tb_note.*,answ.* from tb_note left join";
    $sql .= " (select noan_note_id from tb_note_answer group by noan_note_id) as answ ";
    $sql .= " on answ.noan_note_id = tb_note.note_id ";
    if($_POST[keyword]==""){
    $sql.= " where note_flag=0 order by note_time desc";
    }else{
    $select=$_POST[select];
    $keyword=$_POST[keyword];
    $sql.= " where $select like '%".$keyword."%' and  note_flag=0 order by note_time desc";
    }if($_GET){
    //得到要提取的页码
    $page_num = $_GET['page_num']? $_GET['page_num']: 1;
    }
    else{
    //首次进入时,页码为1
    $page_num = 1;
    }
    //得到总记录数
    $DB = new DB_MySQL();
    $DB->query($sql);
    $row_count_sum=$DB->get_rows();                     
    //每页记录数,可以使用默认值或者直接指定值
    $row_per_page = 10;
    //总页数
    $page_count = ceil($row_count_sum/$row_per_page);
    //判断是否为第一页或者最后一页
    $is_first = (1 == $page_num) ? 1 : 0;
    $is_last = ($page_num == $page_count) ? 1 : 0;
    //查询起始行位置
    $start_row = ($page_num-1) * $row_per_page;
    //为SQL语句添加limit子句
    $sql .= " limit $start_row,$row_per_page";
    //执行查询
    $DB->query($sql);
    $res = $DB->get_rows_array();
    //结果集行数
    $rows_count=count($res);
    ?>
    <script language="JavaScript">
    //反选表单中checkbox
    function inverse(form){
    for (var i=0;i<form.elements.length-2;i++){
    var e = form.elements[i];
    e.checked == true ? e.checked = false : e.checked = true;
    }
    }
    //选择表单中所有check_box
    function check_all(form){
    for(var i=0;i<form.elements.length-2;i++){
    var e=form.elements[i];
    e.checked=true;
    }
    }
    </script>
    <html>
    <head>
    <title>07级国防生留言板</title>
    <meta http-equiv="Content-Type" content="text/html;charset=gb2312">
    <link rel="stylesheet" type="text/css" href="../css/css.css">
    </head>
    <body>
    <table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="3"><?php include("m_header.html");?></td>
      </tr>
      <tr>
        <td width="190" valign="top" background="../images/xline.jpg" bgcolor="#F7F7F7"><?php include("m_left.php");?></td>
        <td width="757" valign="top" bgcolor="#FFFFFF"><table width="757" cellpadding="0" cellspacing="0" border="0" bgcolor="#ffffff">
            <tr align="left">
              <td height="50" align="right" bgcolor="#D9EBB9" class="border"><table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" >
                  <tr height="24">
                    <td width="765" height="52" background="../images/right.jpg">&nbsp;</td>
                  </tr>
                </table>
                <table width="757" border="0" align="center" cellpadding="0" cellspacing="0" class="tb1">
                  <form action="./note_delete.php" method="post" name="note" id="note">
                    <tr align="left">
                      <td class="border"></td>
                    </tr>
                    <tr class='style1'>
                      <td width='42' height="26" align="center" bgcolor="D9EBB9">选择</td>
                      <td width='274' align="center" bgcolor="D9EBB9">标题</td>
                      <td width='141' align="center" bgcolor="D9EBB9">作者</td>
                      <td width='139' align="center" bgcolor="D9EBB9">是否回复</td>
                      <td width='161' align="center" bgcolor="D9EBB9">发布时间</td>
                    </tr>
                    <?php
    $col1 = "#ffffff"; //设置记录行背景颜色为白色
    $col2 = "#f0f0f0"; //设置记录行背景颜色为灰色
    $col = $col2;
    for($i=0;$i<$rows_count;$i++){
    //记录行背景色交替
    if($col == $col1)
    $col = $col2;
    else
    $col = $col1;
    $title=$res[$i]['note_title']; //标题
    $author = $res[$i]['note_user']; //作者
    $time = $res[$i]['note_time']; //时间
    $answer = $res[$i]['note_answer']; //回复标记
    $id = $res[$i]['note_id']; //当前行note_id
    ?>
                    <tr valign="middle" bgcolor="<?php echo $col;?>" height="24">
                      <td align="center"><input type="checkbox" name="note_id[]"  value="<?php echo $id;?>" /></td>
                      <td><!-- 在标题上添加连接 -->
                        <a href="note_read.php?note_id=<?php echo $id?>" target="_blank"><?php echo $title;?></a></td>
                      <!-- 作者 -->
                      <td><?php echo $author;?></td>
                      <td align="center"><?php if($answer==0){ echo "未回复"; }else{ echo "已回复";}?></td>
                      <td><?php echo $time;?></td>
                    </tr>
                    <?php
    }
    ?>
                    <tr align="right" bgcolor="#F0F0F0" valign="middle">
                      <td height="28" colspan="2" align="left" bgcolor="F8F7EB">&nbsp;&nbsp;<img src="../images/arrow_ltr.gif" width="38" height="22" />
                        <input type="checkbox" name="select_all" onClick="check_all(this.form)" />
                        <span class="style1">全选</span>&nbsp;&nbsp;
                        <input type="checkbox" name="select_reverse" onClick="inverse(this.form)" />
                        <span class="style1">反选</span>&nbsp;&nbsp;
                        <input name="submit" type="submit" value = " 删除 " class="btn1" />                  </td>
                      <td colspan="3" align="right" bgcolor="F8F7EB">共[<strong><?php echo $row_count_sum;?></strong>]条&nbsp;每页[<strong><?php echo $row_per_page;?></strong>]条/共[<strong><?php echo $page_count;?></strong>]页&nbsp;
                        <!--  分页显示控制链接 -->
                        <?php
    if(!$is_first){
    ?>
                        <a href="./index.php?page_num=1"> 第一页</a> <a href="./index.php?page_num= <?php echo ($page_num-1) ?>">上一页</a>
                        <?php
    }
    else{
    ?>
    第一页&nbsp;&nbsp;上一页
    <?php
    }
    if(!$is_last){
    ?>
                        <a href="./index.php?page_num=<?php echo ($page_num+1) ?>">下一页</a> <a href="./index.php?page_num=<?php echo $page_count ?>">最后一页</a>
                        <?php
    }
    else{
    ?>
                        下一页&nbsp;&nbsp;最后一页
                        <?php
    }
    ?></td>
                    </tr>
                    <tr>
                      <td ></td>
                      <td colspan="4" height="5"></td>
                    </tr>
                  </form>
                </table>
               <form name="form1" method="post" action="index.php">
    查询条件:
    <select name="select">
                    <option value="note_title">留言主题</option>
                    <option value="note_user">留言作者</option>
                    <option value="note_answer">是否回复</option>
                    <option value="note_time">发布时间</option>
                  </select>
    <input name="keyword" type="text" id="keyword" size="30">
    <input type="submit" name="Submit" value="查询">
    &nbsp;&nbsp;
                </form>          </td>
            </tr>
        </table></td>
      </tr>
      </table>
      

  6.   

    什么乱七八糟,看的我也晕,看看我的,这是写入部分
    +++++++++++++++++++++++++++++++++++++++++
    $name=$_POST['name'];
    $text=$_POST['text'];//把POST的数转换成 $变量if ($_SERVER["HTTP_X_FORWARDED_FOR"]=="")
    {
    $ip=$_SERVER["REMOTE_ADDR"];
    }  else
    {
    $ip=$_SERVER["HTTP_X_FORWARDED_FOR"];
    }//这个是检查IP的  $conn = @mysql_connect("localhost","root","80000") or die("无法连接到数据库,失败!");
    //连接数据库,失败的话则提示
    @mysql_select_db("sun",$conn) or die("选择的库不存在或不可用!");//选择数据库,sun为数据库名  $sql="insert into ddaa(id,name,text)     
    values (default,'$name','$text')";   
     
    //这里的ddaa是表名而不是数据库名,提交入表  // 测试的时候可以写 echo $sql; echo "发送完毕!"; mysql_query("set names GB2312");
    //强行把编码转为GB2312,你的IE是用什么就换为什么,,查看--->编码,防止乱码
    $result = @mysql_query($sql,$conn) or die(mysql_error());
      mysql_close($conn);
    //关闭