Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/81587-how-would-i-go-about-doing-this/
Share on other sites

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.';

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.

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

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.

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?

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

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

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?

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.