Xyphon Posted December 13, 2007 Share Posted December 13, 2007 Hey, I ahve a few tihngs done, login, logout, register, ban, ect. I would like to know, how would I go aobut makign a news comments system. I will make the news with simple tables and echo, no hard things, just edit from host. But I would like to know how a comment system would be made. I would like to display users name, which is of course easy, but I dotn know how to put it so it displays every users name that postred.. Basically, I have no clue how to go about doing this. Can someone tell me some pointers, and tell me how to do this? Thank you, Xyphon. Quote Link to comment Share on other sites More sharing options...
trq Posted December 13, 2007 Share Posted December 13, 2007 You'd probably find the solution to this type of functionality by looking at some tutorials about creating a blog. It really is a pretty straight forward task, but this isn't really the place for tutorials. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 Comment Database table id_comment - INT(11) id_user - VARCHAR(225) title - VARCHAR(225) comment - LONGTEXT date - DATE TIME Basically, create form, then validate the data, and in addition to that, just use // Validate for empty fields, long strings, ...etc // If no errors, then put it in the database $username = $_SESSION['username']; $title = $_POST['title']; $comment = $_POST['comment']; $date = date("Y-m-d h:i:s"); mysql_query("INSERT INTO comments (id_user,title,comment,date) values ('$username','$title','$comment','$date')") or die(mysql_error()); echo 'comment has been posted, thankyou.'; Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 13, 2007 Author Share Posted December 13, 2007 Comment Database table id_comment - INT(11) id_user - VARCHAR(225) title - VARCHAR(225) comment - LONGTEXT date - DATE TIME Basically, create form, then validate the data, and in addition to that, just use // Validate for empty fields, long strings, ...etc // If no errors, then put it in the database $username = $_SESSION['username']; $title = $_POST['title']; $comment = $_POST['comment']; $date = date("Y-m-d h:i:s"); mysql_query("INSERT INTO comments (id_user,title,comment,date) values ('$username','$title','$comment','$date')") or die(mysql_error()); echo 'comment has been posted, thankyou.'; How would I make a comment input type? for form. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 <table width="39%" border="0" align="center" cellpadding="0" cellspacing="2"> <tr align="left" valign="top"> <td>Title:</td> <td><input name="title" type="text" id="title" value="RE:"></td> </tr> <tr align="left" valign="top"> <td>Comment:</td> <td><textarea name="comment" cols="60" rows="10" id="comment"></textarea></td> </tr> <tr align="left" valign="top"> <td width="18%"> </td> <td width="82%"><input type="submit" name="Submit" value="Post Comment"></td> </tr> </table> This is what you mean? Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Author Share Posted December 14, 2007 I just ment the Texterea, but thanks. Umm.. Do you know how to go to view? Thats one I really dont understand is how to display the information. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 Comment Database table id_comment - INT(11) id_user - VARCHAR(225) title - VARCHAR(225) comment - LONGTEXT date - DATE TIME Basically, create form, then validate the data, and in addition to that, just use // Validate for empty fields, long strings, ...etc // If no errors, then put it in the database $username = $_SESSION['username']; $title = $_POST['title']; $comment = $_POST['comment']; $date = date("Y-m-d h:i:s"); mysql_query("INSERT INTO comments (id_user,title,comment,date) values ('$username','$title','$comment','$date')") or die(mysql_error()); echo 'comment has been posted, thankyou.'; Thats how. Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Author Share Posted December 14, 2007 Oh I dont mean that. I mean viewcomments.php. And, whats wrong here? <?PHP include('Connect.php'); include('top.php'); $submit = $_POST['submit']; $username = $_SESSION['username']; $comment = $_POST['comment']; if ($submit) { mysql_query("INSERT INTO news_comments (id_user,comment) values ('$username','$comment')") or die(mysql_error()); echo "The comment is successfully posted. Please go <a href='index.php'>back</a>"; } else echo " <html> <form id='frm' method='POST'> <input type='hidden' name='submit' value='1'><br> <textarea name='comment' cols='60' rows='10' id='comment'></textarea><br> <input type='submit' value='Post Comment'> </form> </html>"; include('bottom.php'); exit; ?> I know it wont put in user, since I didnt check for cookie. But why wont it say comment? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 Your form has no action <form id='frm' method='POST'> Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Author Share Posted December 14, 2007 Its not supposed to lead anywhere else. It's just supposed to edit DB. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 Its not supposed to lead anywhere else. It's just supposed to edit DB. So then you put <form action = "" Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Author Share Posted December 14, 2007 The comment is still empty. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 Your form is really clumsy lol try <?php include('Connect.php'); include('top.php'); $submit = $_POST['submit']; $username = $_SESSION['username']; $comment = $_POST['comment']; if ($submit) { mysql_query("INSERT INTO news_comments (id_user,comment) values ('$username','$comment')") or die(mysql_error()); echo "The comment is successfully posted. Please go <a href='index.php'>back</a>"; } else echo " <html> <form action="" method='POST' id='frm'> <input type='hidden' name='submit' value='1'><br> <textarea name='comment' cols='60' rows='10' id='comment'></textarea><br> <input name="submit" type='submit' id="submit" value='Post Comment'> </form> </html>"; include('bottom.php'); exit; ?> Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Author Share Posted December 14, 2007 One, you have else ?> Two, I edited it to ( Three, now I have a stupid Parse error: parse error, unexpected $ in /home/www/ptcrpg.awardspace.com/postcomment.php on line 27 Eww. I dont see anything wrong O.O Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Author Share Posted December 14, 2007 Fixed it, but it stll displays 0 in comments. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 try <?php include('Connect.php'); include('top.php'); $submit = $_POST['submit']; $username = $_SESSION['username']; $comment = $_POST['comment']; if ($submit) { mysql_query("INSERT INTO news_comments (id_user,comment) values ('$username','$comment')") or die(mysql_error()); echo "The comment is successfully posted. Please go <a href='index.php'>back</a>"; } else echo " <html> <form action=\"\" method='POST' id='frm'> <input type='hidden' name='submit' value='1'><br> <textarea name='comment' cols='60' rows='10' id='comment'></textarea><br> <input name=\"submit\" type='submit' id=\"submit\" value='Post Comment'> </form> </html>"; include('bottom.php'); exit; ?> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 Fixed it, but it stll displays 0 in comments. Is there any data in the DB ? Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Author Share Posted December 14, 2007 Yes there is data. Heres my Create ID_COMMENT INT(11) NOT NULL ID_USER BIGINT(255) NOT NULL COMMENT BIGINT(255) NOT NULL Thats not my file, howver. But its what I used in the inside. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 Post the viewcomments code. Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 14, 2007 Share Posted December 14, 2007 you use bigint(number) in your comment ? Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Author Share Posted December 14, 2007 Nono, I dont have it. I ment it displays 0 in the db. Also, It wont display user... O,o teng84: NO! My Create! Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 14, 2007 Share Posted December 14, 2007 if you declare your field as number and you insert strings i believe it will give you 0 Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 id_comment - INT(11) id_user - VARCHAR(225) title - VARCHAR(225) comment - LONGTEXT date - DATE TIME Quote Link to comment Share on other sites More sharing options...
Xyphon Posted December 14, 2007 Author Share Posted December 14, 2007 id_comment - INT(11) id_user - VARCHAR(225) title - VARCHAR(225) comment - LONGTEXT date - DATE TIME Nah, I dont want title and date. But you cant put dashes, do you mean ID_COMMENT INT(11) NOT NULL, ID_USER VARCHAR(225) ECT And why wont it display user? Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 14, 2007 Share Posted December 14, 2007 I'm lost can you explain now your problem? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.