开发者

Having issue with the $id_get['id '] function

开发者 https://www.devze.com 2023-02-03 08:15 出处:网络
I want to be able to call the comment that users make on a picture on the same page as the pic. and when a different page comes up that comment for that pic is displayed also. I am able to that, but I

I want to be able to call the comment that users make on a picture on the same page as the pic. and when a different page comes up that comment for that pic is displayed also. I am able to that, but I can't seem to call the URL for that pic without changing the actual code.

开发者_JS百科
<?
include.....

$picid = $_GET['picid'];
$query = mysql_query("SELECT * FROM pic_info WHERE picid = 'picid1' ");// problem

while($rows = mysql_fetch_assoc($query)):
$picid = $rows['picid'];
$title = $rows['title'];
$link = $rows['link'];
$description = $rows['description'];
$movie_pic = $rows['movie_pic'];
$source = $rows['source'];

endwhile;

$get_comment = mysql_query("SELECT * FROM comment WHERE picid ='$picid'");// work partially
$comment_count = mysql_num_rows($get_comment);
if ($comment_count>0)
{
while ($com = mysql_fetch_array($get_comment)){
$comment_id = $com['comment_id'];
$name = $com['name'];
$message = $com['message'];
$time_post= $com['time_post'];
$messages .= '<em> on ' .$time_post.'</em><b>   '.$name.'   said.....</b><br/> '.$message.'<hr/>';
}
?>

Problem: only works if I change picid1 to some thing else like picid2 or 3 or 4... work partially :: works when I change picid1 to some thing else like picid2 or 3 or 4... other than that it comes up saying no comment.

I'm not sure if the problem is at top, cant figure it out.


you are missing a $...

WHERE picid = '$picid'

Soemething like this:

$picid = $_GET['picid'];
$query = mysql_query("SELECT * FROM pic_info WHERE picid = '$picid' ");

To be in the safe side... I would actually do this

$picid = mysql_real_escape_string($_GET['picid']);
$query = mysql_query("SELECT * FROM pic_info WHERE picid = '$picid' ");

Why? Read here

BTW, if picid is a number type, I would omit the quotes...

 WHERE picid = $picid

---- EDIT ------

if ($comment_count>0)
{
  $messages = ""; //added this
  while ($com = mysql_fetch_array($get_comment)){
    $comment_id = $com['comment_id'];
    $name = $com['name'];
    $message = $com['message'];
    $time_post= $com['time_post'];
    $messages .= '<em> on ' .$time_post.'</em><b>   '.$name.'   said.....</b><br/>'.$message.'<hr/>';
  }
} // added this...
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消