插入语句为什么只有两个字段插入进去?tpid总是为0,在插入语句前能输出tpid的值的
if($_POST["submit"]=="提交"  ){
         $tpid=$_POST[tpid];
$content=$_POST[txt_content];
$datetime=date("Y-m-d H:i:s");
echo "$tpid";
$INS="Insert Into tb_comment (content,datetime,tpid) Values ('$content','$datetime','$tpid')";
$info=mysql_query($INS);
if($info){

echo "<script> alert('成功发表评论!');</script>";
echo "<script> window.location.href='$_SERVER[HTTP_REFERER]';</script>";
}
else{
echo "<script> alert('评论发表操作失败!');</script>";
echo "<script> history.go(-1);</script>";
}
}

解决方案 »

  1.   

    tpid 字段的属性值是int --------->$tpidtpid 字段的属性值是char --------->"$tpid"
      

  2.   

     我试了,在表单那一页传过来的id输出是:\'26\'
    在处理表单那一页传过来的id输出是: \\\'26\\\'
      

  3.   

    把表tpid字段属性改为char即可 其它不变
      

  4.   

    这样改变属性值为char之后,数据库存储的tpid为\'26\'
    但是  我要根据图片的id来评论的数据表里找与它相对应的评论内容啊,这样图片的id是int型,而保存在评论里的图片id是char,这就找不到了呀,要怎么办???
      

  5.   

    用的时候转换一下了<?php
    $x="\'26\'";
    $y= str_replace("\'","",$x);
    echo $y;?>
      

  6.   

    我要在显示图片大图那一页显示该图片的评论,显示大图的时候有获得图片的id,那我要怎么把在评论数据表中的tpid  char型转换成int型,并且与图片的id对应起来,我这样转换不对,没理清逻辑,帮忙修改
    <?php if($_GET['id']){
       $id=$_GET['id'];
       //echo"$id";
       $query=mysql_query("select * from tb_tpsc where id='$id'",$conn);
       $row=mysql_fetch_array($query); 
       echo "<img src='$row[tpmc]'>";//显示大图
       //echo "$id";
       echo  "<a href=commentform.php?tpid='$id'>评论图片</a>";//ID已经GET形式传递,评论页可以$_GET['id']获取到图片ID
       }
       ?></div></td>
      </tr>
      <tr>
        <td> <?php  
    $query2=mysql_query("select * from tb_comment1 ",$conn);
        $row2=mysql_fetch_array($query2); {
       
        $x="$row1[id]";
        $y= str_replace("\'","",$x);
       echo $y;
      }
    ?>

    <?php $query1=mysql_query("select * from tb_comment1 where id='$y' order by datetime desc",$conn);
       $row1=mysql_fetch_array($query1); 
       
       echo $row1[content];
       ?>
      

  7.   

    <?php if($_GET['id']){
       $id=$_GET['id'];
       //echo"$id";
       $query=mysql_query("select * from tb_tpsc where id='$id'",$conn);
       $row=mysql_fetch_array($query);  
      echo "<img src='$row[tpmc]'>";//显示大图
       //echo "$id";
       echo "<a href=commentform.php?tpid='$id'>评论图片</a>";//ID已经GET形式传递,评论页可以$_GET['id']获取到图片ID
       }
       ?>
    </div></td>
       </tr>
       <tr>
       <td> 
    /*----------------------上面不是显示大图了嘛*//*----------------------下面为所对应的图片评论*/
     
    <?php $query1=mysql_query("select * from tb_comment1 where id='$row[id]' order by datetime desc",$conn);
       $row1=mysql_fetch_array($query1);  
        
      echo $row1[content];
       ?>
    这样不行吗?
      

  8.   

    图片的ID和评论的ID不一样,它们各自在不同的数据表中,所以我就把图片的ID存在评论表的tpid字段中,现在是我要让图片的ID和评论表中的tpid相同,但是它们的类型不一样,所以要转换,我又不知道怎么转换