当我添加评论时,我收到此警告

时间:2012-10-19 17:58:26

标签: php mysql comments

你好我们这个代码有问题

当id在数据库中添加注释和注释插入时 当我在同一页面刷新时,我收到此警告: 其中一个字段仍然是空的, 我认为第一个代码中的问题

    <?php 

    if ($_POST['add'] and $_POST['add']=='comm'){

    $comm_name      =strip_tags($_POST['comm_name']);
    $comm_country   =strip_tags(mysql_real_escape_string($_POST['comm_country']));
    $c              =strip_tags(mysql_real_escape_string($_POST['comm']));
    $comm_thread    =strip_tags(mysql_real_escape_string($_POST['comm_thread']));
    $status =$_POST['status'];
    $getidtopic=$_GET['id_topic'];
    $post_code=$_POST['post_code'];

    if ($comm_name=='' or $comm_country=='' or $c=='' or $post_code=='' ){
    echo "<script>alert(\"One of the fields are still empty
\");</script>";
    }else if ($_POST['post_code']==$_SESSION['code']) {

    $insertcomm=mysql_query("insert into comments values('','$comm_name','$comm_country','$comm','$comm_thread','$status') ")or die (mysql_error);
    echo "<script>alert(\"your comment has been adding\");</script>";

    }
    }


    ?>

,这是评论的形式

    <form action='' method='post' >
    <table  class='rightcol'  width='100%' cellpadding='0' cellspacing='5'>


    <tr>
    <td colspan='3' id='addcomm'>add comm</td>

    </tr>

    <tr>

    <td width='15%' ><div id='title_comm' value=''>name : </div></td>
    <td  ><input type='text' name='comm_name' value='<?if (!$insertcomm){
    echo $comm_name;
    }?>'/></td>
    </tr>

    <tr>
    <td width='15%' ><div id='title_comm'>country  </div></td>
    <td ><input type='text' name='comm_country' 
    value='<?if (!$insertcomm){echo $comm_country;}?>'/>
    </td>
    </tr>


    <tr>
    <td valign='top' width='15%'><div id='title_comm'>comment : </div></td>
    <td width='50%'>
    <textarea  cols='55' rows='12' name='comm'>
    <?if (!$insertcomm){echo $c;}?>
    </textarea></td>
    <td valign='top' ><div id='note_comm'>
  your comment will not insert if you try to use some thing bad
    </div></td>
    </tr>


    <tr>
    <td width='15%' ><div id='title_comm'><span style='color:red'>code : <br/>write these codes </span></div></td>
    <td ><input type='text' name='post_code'/></td>
    </tr>

    <tr>
    <td ><div id='code'>
    <?php 
    $text=rand(400,80000);
    echo $_SESSION['code']=$text;
    ?>


    </div></td>
    </tr>




    <td colspan='4' ><input type='submit' name='addcomm' id='add' value='add comm'/></td>

    </table>
    <input type='hidden' name='comm_thread' value='<?php echo $getidtopic;?>' />
    <input type='hidden' name='add' value='comm'/>
    <input type='hidden' name='status' value='2'/>
    </form>

2 个答案:

答案 0 :(得分:0)

这是因为,当您刷新页面时,$_POST字段将被重置,并且字段变为空,因此当页面执行其PHP行if ($comm_name=='' or $comm_country=='' or $c=='' or $post_code=='' or $post_code=='' ){时,它将发现它们为空。

答案 1 :(得分:0)

您需要向我们展示表格定义,以便更好地找出问题的确切原因。我的猜测是你的SQL语句没有准备好。