想把图片id传给两个页面
我在showphoto.php页点击缩略图取得图片id,想把它传给show.php页显示大图,在大图下面写有“评论图片”,然后想点击“评论图片”这几个字又传给图片评论那一页comment.php,把每个评论内容和图片的id对应起来,所以我要把图片的id写进评论数据表中,其字段是tpid
下面是我的代码showphoto.php 这页是显示缩略图
$query=mysql_query("select * from tb_tpsc where type='达人收藏' order by id desc limit ".($page_num-1)*$row_per_page." ,$row_per_page",$conn);
while($row=mysql_fetch_array($query))
{
echo "<a href=show.php?id=".$row[id]."><img widht=100 height=100 src='$row[tpmc]'></a>";
}show.php 这也是显示大图
<?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
}
?>
commentform.php 这页是评论表单 <form name="myform" method="post" action="commentadd.php">
<table width="560" border="1" align="center" cellpadding="3" cellspacing="1" bordercolor="#9CC739" bgcolor="#FFFFFF">
<tr align="left" colspan="2" >
<td width="390" height="25" colspan="3" valign="top" bgcolor="#EFF7DE"> <span class="right_head"><SPAN style="FONT-SIZE: 9pt; COLOR: #cc0033"></SPAN></span><span class="tableBorder_LTR"> 发表评论</span> </td>
</tr>
<td height="112" align="center" valign="top" >
<input name="tpid" type="hidden" value="<?php echo $_GET[tpid];?>">
<?php echo "$_GET[tpid]";?>
<table width="500" border="1" cellpadding="1" cellspacing="0" bordercolor="#D6E7A5" bgcolor="#FFFFFF">
<tr>
<td align="center">我要评论</td>
<td width="410"><textarea name="txt_content" cols="66" rows="8" id="txt_content" ></textarea></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="submit" value="提交" onClick="return check();">
<input type="reset" name="submit2" value="重置"></td>
</tr>
</table> </td>
</table>
</form>commentadd.php 这页是处理表单数据写进数据库
<?php//echo "$_POST[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')";
echo"$INS";
$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传到commentform.php 页时,输出的id就变成字符的去了如第图片id为26的在这一页输出的就是\'26\'
后面那一页就无法获得id写进数据库
这是怎么回事??求指点
我在showphoto.php页点击缩略图取得图片id,想把它传给show.php页显示大图,在大图下面写有“评论图片”,然后想点击“评论图片”这几个字又传给图片评论那一页comment.php,把每个评论内容和图片的id对应起来,所以我要把图片的id写进评论数据表中,其字段是tpid
下面是我的代码showphoto.php 这页是显示缩略图
$query=mysql_query("select * from tb_tpsc where type='达人收藏' order by id desc limit ".($page_num-1)*$row_per_page." ,$row_per_page",$conn);
while($row=mysql_fetch_array($query))
{
echo "<a href=show.php?id=".$row[id]."><img widht=100 height=100 src='$row[tpmc]'></a>";
}show.php 这也是显示大图
<?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
}
?>
commentform.php 这页是评论表单 <form name="myform" method="post" action="commentadd.php">
<table width="560" border="1" align="center" cellpadding="3" cellspacing="1" bordercolor="#9CC739" bgcolor="#FFFFFF">
<tr align="left" colspan="2" >
<td width="390" height="25" colspan="3" valign="top" bgcolor="#EFF7DE"> <span class="right_head"><SPAN style="FONT-SIZE: 9pt; COLOR: #cc0033"></SPAN></span><span class="tableBorder_LTR"> 发表评论</span> </td>
</tr>
<td height="112" align="center" valign="top" >
<input name="tpid" type="hidden" value="<?php echo $_GET[tpid];?>">
<?php echo "$_GET[tpid]";?>
<table width="500" border="1" cellpadding="1" cellspacing="0" bordercolor="#D6E7A5" bgcolor="#FFFFFF">
<tr>
<td align="center">我要评论</td>
<td width="410"><textarea name="txt_content" cols="66" rows="8" id="txt_content" ></textarea></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="submit" value="提交" onClick="return check();">
<input type="reset" name="submit2" value="重置"></td>
</tr>
</table> </td>
</table>
</form>commentadd.php 这页是处理表单数据写进数据库
<?php//echo "$_POST[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')";
echo"$INS";
$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传到commentform.php 页时,输出的id就变成字符的去了如第图片id为26的在这一页输出的就是\'26\'
后面那一页就无法获得id写进数据库
这是怎么回事??求指点
在showphoto.php页面再次输出id号到两个链接里就行了。
后面那一页就无法获得id写进数据库
这个后面那一页是什么后面那一页?有个问题希望你修改下 你的$_GET 或者 $_POST 都修改成 $_GET['XXXX'] 或者 $_POST['XXXX'] 当然双引号也是可以的。