Jump to content

linking comment systen to template page


Recommended Posts

Ok. Thought I'd be able to do this myself but ran into a couple of snags. This is the template page for the image thumbnails. WHen a thumbnail is clicked it is dragged into this template. I put the code for the comments on the page but it's just not working properly. When I post comment the comment posts but the picture turns into my BAD PHOTO ID error message. Have some ideas on whats going but it's getting kind of messy. If you need to see the pages from the comment system I will post. Thanks phpeople. Where's fugix?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>What do you know about.......</title>
<style type="text/css">
#What {
text-align: center;
}
</style>
</head>

<body>
<div id="What"><img src="images/what.png" width="477" height="36"  alt="do you know something i don't" /></div>
<?php
$hostname='fd.db.fdffd.d.com';
$username='d';
$password='d!';
$dbname='d';
$usertable='d';

mysql_connect('yd.com', 'yd9', 'Ad!') or die(mysql_error());
mysql_select_db("yd9") or die(mysql_error());

$id = (int)$_GET['id'];
if( $id > 0 ) {
  $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error());
  
  $row = mysql_fetch_array( $result );
  echo " <img src=\"/{$row['photopath']}\" height=\"400px\" width=\"400px\" />". "<br />
";
  echo $row['name']. "\n". "<br/>";
  echo $row['state']. "\n";
} else {
  echo 'BAD PHOTO ID';
}
?>
<?php
$hostname='durce.com';
$username='yod9';
$password='Ad1!';
$dbname='yd';
$usertable='d';

mysql_connect('yd, 'yd9', 'Ad!') or die(mysql_error());
mysql_select_db("yd") or die(mysql_error());

$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['submit'];
if($submit)
{
    if($name&&$comment)
    {
    $query=mysql_query("INSERT INTO comment (id,name,comment) VALUES ('','$name','$comment')");
    }
    else
    {
        echo "Please fill out all the fields.";
    }
}
?>
<body>

<div id="comments">
<form action="image_show.php" method="POST">
<label>Name:  </label><br /><input type="text" name="name" input id="name"value="<?php echo "$name" ?>" /><br /><br />
<label>Comment:  </label><br /><input type="text" input id="comment"/><textarea name="comment" "cols="25" rows="7"></textarea><br /><br /><br />
<input type="submit" name="submit" value="Comment" /><br />

</form></div>
<hr width="1100px" size="5px" />
</body>
<?php

$query=mysql_query("SELECT * FROM comment ORDER BY id DESC");
while($rows=mysql_fetch_assoc($query))
{
     $id=$rows['id'];
     $name=$rows['name'];
     $comment=$rows['comment'];
     $linkdel="<a href=\"delete.php?id=" . $rows['id'] . "\">Delete User</a>";
     echo '<font color="red">Name:</font>  ' . $name . '<br />' . '<br />' . '<font color="red">Comments:</font>  ' . '<br />' . $comment . '&nbsp' . '&nbsp' .
      '&nbsp' . '&nbsp' .  $linkdel . '<br />' . '<br />' . 
     '<hr size="5px" width="500px" color="blue" />'  ;    
}
?>
</html>
</body>
</html>

Link to comment
Share on other sites

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

that id is the id of the thumbnail thats clicked. It drags all the info into the template. That all works fine but once I put the comment system in I'm getting Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/20/7812420/html/comment.php on line 33. ANd if I do post a comment the photo disappears with a  BAD PHOTO ID error message. This is a comment system I wrote to stand alone so would it be easier to re-write one into the page. The comment page also uses success.php connect.php and delete.php

Link to comment
Share on other sites

well your bad photoid error comes from this

$id = (int)$_GET['id'];
if( $id > 0 ) {
  $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error());
  
  $row = mysql_fetch_array( $result );
  echo " <img src=\"/{$row['photopath']}\" height=\"400px\" width=\"400px\" />". "<br />
";
  echo $row['name']. "\n". "<br/>";
  echo $row['state']. "\n";
} else {
  echo 'BAD PHOTO ID';
}

 

so what i would do is echo the id before running the if statement to see if i am returning anything

$id = (int)$_GET['id'];
echo $id;
if( $id > 0 ) {
  $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error());
  
  $row = mysql_fetch_array( $result );
  echo " <img src=\"/{$row['photopath']}\" height=\"400px\" width=\"400px\" />". "<br />
";
  echo $row['name']. "\n". "<br/>";
  echo $row['state']. "\n";
} else {
  echo 'BAD PHOTO ID';
}

Link to comment
Share on other sites

i think that you are receiving that error because your form action is not dynamic...meaning that it is not sending an id to itself...so when this

$id = (int)$_GET['id'];

tries to retrieve an id...it doesn't receive one, and you get your error, you need to make your form send an id like this

<form action="image_show.php?id=1" method="POST">

and you would replace the one with whatever the id is supposed to be

 

Link to comment
Share on other sites

alright i think i see whats going on. The comments are posting they are being pulled from db when thumbnail is clicked but photo still disappears when posting a comment. The url goes from having an id say 48 before posting to going to id=$id after with no pic.

Link to comment
Share on other sites

there is no proper id. It's whatever photo the user clicks. It's not my own gallery it's uploaded photos from users that go into a main page then when clicked enter the template. And whats happening is when the page is run again to publish the comment the pic disappears. Not when first called.

Link to comment
Share on other sites

that gets the id of the picture selected. When you go to the gallery and click a photo the photo opens in the template comments below it, url displaying id then when you publish a comment and the page refreshes then the pic disappears and id goes to id=$id and even img src has no path for the image.

 

before comment: <img src="/uploads/photo_12.png" height="400px" width="400px" /><br />

 

after comment: BAD PHOTO ID <img src="/" height="400px" width="400px" /><br />

:shrug:

Link to comment
Share on other sites

sorry I was getting confused. That id is coming from this page where all the photos are uploaded to.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>The List</title>
<style type="text/css">
#a {
text-decoration: none;
}
</style>
</head>

<body>

<div id="header"></div>


<?php require_once('myconn.php');

if (!function_exists("GetSQLValueString")) {
  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
    if (PHP_VERSION < 6) {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    }
    
    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
    switch ($theType) {
      case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
      case "long":
      case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
      case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
      case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
      case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
    }
    return $theValue;
  }
}

$maxRows_Recordset1 = 40;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_myconn, $myconn);
//Added ID
$query_Recordset1 = "SELECT `id`, `name`, `photopath`, `state` FROM photo ORDER BY `name` ASC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $myconn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<div id="photos">
  <table border="1" bordercolor="#000000">
    <?php $i=0;
    $numperpage=10; ?>
    <?php do { ?>
      <?php if ($i%$numperpage==0) echo "<tr>"; ?>
    <td align="center">
      
      <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src='<?php echo $row_Recordset1['photopath'] ;?>' height="100" width="100"/></a>
      <br/>
<?php echo $row_Recordset1['name']; ?><br/> <?php echo $row_Recordset1['state']; ?></td>
      <?php $i++;
      if ($i%$numperpage==0) echo "</tr>"; ?>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  </table>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
</body>
</html>

Link to comment
Share on other sites

okay so let me get organized here when you click this link

<a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src='<?php echo $row_Recordset1['photopath'] ;?>' height="100" width="100"/></a>

everything works as it should....the picture shows and everything, however when someone writes and comment and hits the submit button...the image does not show anymore?

Link to comment
Share on other sites

okay so you're going to try this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>What do you know about.......</title>
<style type="text/css">
#What {
text-align: center;
}
</style>
</head>

<body>
<div id="What"><img src="images/what.png" width="477" height="36"  alt="do you know something i don't" /></div>
<?php
$hostname='fd.db.fdffd.d.com';
$username='d';
$password='d!';
$dbname='d';
$usertable='d';

mysql_connect('yd.com', 'yd9', 'Ad!') or die(mysql_error());
mysql_select_db("yd9") or die(mysql_error());

$id = (int)$_GET['id'];
if( $id > 0 ) {
  $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error());
  
  $row = mysql_fetch_array( $result );
  echo " <img src=\"/{$row['photopath']}\" height=\"400px\" width=\"400px\" />". "<br />
";
  echo $row['name']. "\n". "<br/>";
  echo $row['state']. "\n";
} else {
  echo 'BAD PHOTO ID';
}
?>
<?php
$hostname='durce.com';
$username='yod9';
$password='Ad1!';
$dbname='yd';
$usertable='d';

mysql_connect('yd, 'yd9', 'Ad!') or die(mysql_error());
mysql_select_db("yd") or die(mysql_error());

$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['submit'];
if($submit)
{
    if($name&&$comment)
    {
    $query=mysql_query("INSERT INTO comment (id,name,comment) VALUES ('','$name','$comment')");
    }
    else
    {
        echo "Please fill out all the fields.";
    }
}
$query_Recordset1 = "SELECT `id`, `name`, `photopath`, `state` FROM photo ORDER BY `name` ASC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $myconn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
?>
<body>

<div id="comments">
<form action="image_show.php?id=<?php echo $row_Recordset1['id'];?>" method="POST">
<label>Name:  </label><br /><input type="text" name="name" input id="name"value="<?php echo "$name" ?>" /><br /><br />
<label>Comment:  </label><br /><input type="text" input id="comment"/><textarea name="comment" "cols="25" rows="7"></textarea><br /><br /><br />
<input type="submit" name="submit" value="Comment" /><br />

</form></div>
<hr width="1100px" size="5px" />
</body>
<?php

$query=mysql_query("SELECT * FROM comment ORDER BY id DESC");
while($rows=mysql_fetch_assoc($query))
{
     $id=$rows['id'];
     $name=$rows['name'];
     $comment=$rows['comment'];
     $linkdel="<a href=\"delete.php?id=" . $rows['id'] . "\">Delete User</a>";
     echo '<font color="red">Name:</font>  ' . $name . '<br />' . '<br />' . '<font color="red">Comments:</font>  ' . '<br />' . $comment . '&nbsp' . '&nbsp' .
      '&nbsp' . '&nbsp' .  $linkdel . '<br />' . '<br />' . 
     '<hr size="5px" width="500px" color="blue" />'  ;    
}
?>
</html>
</body>
</html>

 

and let me know what you get

Link to comment
Share on other sites

same. "bad photo id" no url id and when i go to delete a comment the error disappears and all thats left is the comment box and Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/20/7812420/html/comment.php on line 33.

 

Seems like every pass this page takes it loses info. first loses picture then when deleting a comment it loses error

Link to comment
Share on other sites

well i know why your photo id is dissapearing, when you click on the photo link

<a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src='<?php echo $row_Recordset1['photopath'] ;?>' height="100" width="100"/></a>

it is setting the url to image_show.php?id=<?php echo $row_Recordset1['id'];?/>

however, when you post a comment, you have the action set to just image_show.php

therefore when the form is submitted, you are going from a dynamic url to plain image_show.php, thus you lose your id

Link to comment
Share on other sites

no the action has been that way. I changed it while we've been talking. The first code i posted had only image_show.php.

 

Heres the view source. Its odd that the delete function has the id of the photo: <a href="delete.php?id=22">Delete User</a>

BAD PHOTO ID<body>

<div id="comments">
<form action="image_show.php?id=" method="POST">

<label>Name:  </label><br /><input type="text" name="name" input id="name"value="chri" /><br /><br />
<label>Comment:  </label><br /><input type="text" input id="comment"/><textarea name="comment" "cols="25" rows="7"></textarea><br /><br /><br />
<input type="submit" name="submit" value="Comment" /><br />

</form></div>
<hr width="1100px" size="5px" />
</body>
<font color="red">Name:</font>  chri<br /><br /><font color="red">Comments:</font>  <br />jkokjmn&nbsp&nbsp&nbsp&nbsp<a href="delete.php?id=22">Delete User</a>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.