插入语句为什么只有两个字段插入进去?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>";
}
}
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>";
}
}
在处理表单那一页传过来的id输出是: \\\'26\\\'
但是 我要根据图片的id来评论的数据表里找与它相对应的评论内容啊,这样图片的id是int型,而保存在评论里的图片id是char,这就找不到了呀,要怎么办???
$x="\'26\'";
$y= str_replace("\'","",$x);
echo $y;?>
<?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];
?>
$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];
?>
这样不行吗?