Jump to content

linking comment systen to template page


Recommended Posts

its the original post:

<!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>

<?php
$hostname='yoddce.com';
$username='yd29';
$password='Ad1!';
$dbname='d9';
$usertable='do';

mysql_connect('yourdddd!') or die(mysql_error());
mysql_select_db("d") 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=\"350px\" />". "<br />
";
  echo $row['name']. "\n". "<br/>";
  echo $row['state']. "\n";
} else {
  echo 'BAD PHOTO ID';
}
?>
<?php
$hostname='dm';
$username='yd';
$password='d1!';
$dbname='d9';
$usertable='dto';

$myconn=mysql_connect('yddd!') or die(mysql_error());
mysql_select_db("dd") 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>

  • Replies 66
  • Created
  • Last Reply

yes that will need to be changed to, your form and header need to go to the dynamically created page, not the base page okay so change this

$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);
?>

to

$query_Recordset1 = "SELECT * FROM photo";
$Recordset1 = mysql_query($query_Recordset1) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
?>

did you want me to change all this:

 

$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;
?>

 

or just this part:

 

$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);

 

tried it and same old bad photo id but thats with only changing the 5 lines of code above

hey im back...fell asleep last night. i wanted you to change the query code that i posted, for you image_show.php so you would have 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>

<?php
$hostname='yoddce.com';
$username='yd29';
$password='Ad1!';
$dbname='d9';
$usertable='do';

mysql_connect('yourdddd!') or die(mysql_error());
mysql_select_db("d") 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=\"350px\" />". "<br />
";
  echo $row['name']. "\n". "<br/>";
  echo $row['state']. "\n";
} else {
  echo 'BAD PHOTO ID';
}
?>
<?php
$hostname='dm';
$username='yd';
$password='d1!';
$dbname='d9';
$usertable='dto';

$myconn=mysql_connect('yddd!') or die(mysql_error());
mysql_select_db("dd") 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 * FROM photo";
$Recordset1 = mysql_query($query_Recordset1) 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>

hey man. Thanks for coming back. SO i changed that code ran it posted a comment and now instead of getting bad photo id when publishing a comment the url defaults back. example: before php?id=46 after posting: php?id=32

defaults to this photo regardless of the thumbnail clicked but at least there's a photo,right? when you click delete thats when you get a bad photo id

okay well thats good. Basically what you need is however you got the photoid for the pictures...i think you got it from you database...you need to use that same id as your action in your comment form....thats what im trying to do here....if you know what im talking about you will have an easier time doing it since you coded it

thats how i wrote it as well but keep getting syntax errors

 

<?php
require('connect.php');
$deleteid=$_GET['id'];
mysql_query("DELETE FROM comment WHERE id='$deleteid'");
header("Location: image_show.php?id=$row_Recordset1['id']"); // dont know what syntax error
?>

i added {} around row syntax error is gone but when i delete no deletion and back to bad photo id.

 

<?php
require('connect.php');
$deleteid=$_GET['id'];
mysql_query("DELETE FROM comment WHERE id='$deleteid'");
header("Location: image_show.php?id={$row_Recordset1['id']}");
?>

alright whats the error you get when you add this

<?php
require('connect.php');
$deleteid=$_GET['id'];
mysql_query("DELETE FROM comment WHERE id='$deleteid'") or die(mysql_error());
header("Location: image_show.php?id={$row_Recordset1['id']}");
?>

no database selected but here is my connect.php include

 

<?
$con = mysql_connect('a','a','a');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db('a');
?>

 

i feel  i'm insulting you when i take out the db info especially after all the times you've helped.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.