View comments on profile page need help.
Posted: Sun Apr 15, 2012 8:17 pm
ok recently i have been trying to make a simple view comments kind of like facebook like say...
when you post a comment on the users profile under the comment will be a link to see all the comments posted onto that one comment.
things i got to work with this...
- viewing the comment (when clicking view comments brings you to that page)
things that is not working...
- posting the comment onto the new page with the comments from the single comment on the profile page.
- also when i enter the comment it does add it to the database but its not getting the id...
ok so i need help trying to figure out how to get this to work here is what i have so far.
SQL:
user comments:
"also im using the same sql for adding comments on the profile page"
when you post a comment on the users profile under the comment will be a link to see all the comments posted onto that one comment.
things i got to work with this...
- viewing the comment (when clicking view comments brings you to that page)
things that is not working...
- posting the comment onto the new page with the comments from the single comment on the profile page.
- also when i enter the comment it does add it to the database but its not getting the id...
ok so i need help trying to figure out how to get this to work here is what i have so far.
SQL:
user comments:
"also im using the same sql for adding comments on the profile page"
CREATE TABLE IF NOT EXISTS `user_comments` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `text` varchar(50) NOT NULL, `comment` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;the SQL that doesnt add:
INSERT INTO `user_comments` (`id`, `user_id`, `text`, `comment`) VALUES (1, 0, 'Smg', 'Enter your comment');view_comment.php:
<?php include('core/init.inc.php'); $id = $_GET['id']; if(empty($id)) header('Location: index.php'); else { $query = mysql_query("SELECT * FROM user_comments WHERE id = '$id' ORDER BY id DESC"); if (mysql_num_rows($query) == 0) echo 'Be the first to add a comment.<br />'; else { while($output = mysql_fetch_assoc($query)) { echo $output['text'].'<br />'; echo $output['comment'].'<br />'; } } ?> <form method="post" action="user_comment.php?id=<?php echo $id; ?>"> <input type="hidden" name="name" id="name" value="Name" /><br /> <textarea name="comment" id="comment">Enter your comment</textarea><br /> <input type="submit" name="submit" id="submit" value="Submit" /> <input type="hidden" value="'.$id.'" name="id" id="id" /> </form> <?php } ?>user_comment.php:
<?php include('core/init.inc.php'); $id = $_GET['id']; if(empty($id)) header('Location: index.php'); else { function clear($message) { if(!get_magic_quotes_gpc()) $message = addslashes($message); $message = strip_tags($message); $message = htmlentities($message); return trim($message); } if($_POST['submit']) { if (empty($_POST['comment'])) die('Enter a comment.'); $id = $_POST['id']; $msg_title = $_SESSION['user_username']; $msg_message = clear($_POST['comment']); if(mysql_query("INSERT INTO `user_comments` VALUES ('', '', '{$msg_title}', '{$msg_message}')")) echo 'Comment Entered.'; mysql_close(); } } ?>