Making A PHP Script [Comment Feature]

Fait

Seasoned Veteran
Joined
Oct 15, 2010
Messages
4,407
Reaction score
561
FP$
2,054
Ok,

I have made a status feature where people can write statuses on the site.

Now I need A feature where They can comment to a status or if i make A news feature they can comment to news articles

So far I can create Login Systems Chatrooms & Games with php.

Now im onto more advanced stuff.

Help/Advice Is Apreciated
----

Spudster
 
Here's one way to create it:
Create table for comments.
Create say theses 4 rows:
id, comment, userid, postid

Then to get comments just do something like:
SELECT * FROM comments WHERE postid='$thepostsid'
 
I Sort of get it now 😀

So if the Status id is 4 then If the table 'postid is equal to 4 it will display everyrhing the id of 4 guess I will need to get the status ID.

And will i be using the get method then?

Thanks 😉
 
Mr.Shy said:
I Sort of get it now 😀

So if the Status id is 4 then If the table 'postid is equal to 4 it will display everyrhing the id of 4 guess I will need to get the status ID.

And will i be using the get method then?

Thanks 😉

Consider you have a table called posts and a table called comments.

When you are commenting to a post, save the comment in comments table and save the post's ID too.

So when you are inside the post again, you can grab comments from the comments table with post ID as the post's ID.
 
I will start on this in a few days now.
Working on A PM System which is coming along good so far.
Also Ive noticed when a user need todo a new paragraph

like this they need to add <br> todo a line break how can i auto detect this once a user does 1 or more line breaks?

Besides this its coming along very well!
 
I'm just working on something like that Mr.Shy i'll post my results if it works 🙂

Also one way to do it is use this when outputting:
<pre>The Message</pre>
 
Mr.Shy said:
I will start on this in a few days now.
Working on A PM System which is coming along good so far.
Also Ive noticed when a user need todo a new paragraph

like this they need to add <br> todo a line break how can i auto detect this once a user does 1 or more line breaks?

Besides this its coming along very well!

Use PHP's nl2br() function.

Suppose of you have a textbox with name "data" in your form.

Instead of echoing $_POST['data'], echo nl2br($_POST['data'])
 
Oh I completely forgot about that function. :lol:
Thanks kavin.
 
Patrick S. said:
Oh I completely forgot about that function. :lol:
Thanks kavin.

No problems. 😀

Alternatively, it can be achieved through str_replace too, but nl2br is much easier.
 
I was about to use str_replace. It's not as easy and has lots more lines of code 😛
 
Thanks 😀

Im going to limit the amout of characters per pm to 400 Characters by using the strlen() function.
This should help me now

One last question then I should be fine with the rest of the system.
Say if there's 10 PM on the page how do i add a link where they can goto page 2 of the page and every 10 PM Results it adds A new number to the page so inbox.php will be inbox.php?page=3 (becuase having 50 pms on one page will lag and will be messy)

Ive enabled the feature where users can now contact other users threw PMs now ;0

Just A More Tweaks.<br /><br />-- 06 Jul 2012, 10:51 --<br /><br />Also you get follow my updates on facebook (We need likes)

http://facebook.com/admintalkforums/
 
One more issue its a minor issue...

When i make a value
$password = md5($_POST['value']);
and make a function

if (empty($password))
echo "Fields Required"

Its not saying its a false value but true? (wont echo the error)
But when I put

if ($password==true)
echo $password

its echoing A blank md5?

so how can i echo a md5 field out if the user hasnt submited any text??
I have A tempprary solourion but adding md5($password)
on function and leaving it as plain text as a value.
 
Mr.Shy said:
One more issue its a minor issue...

When i make a value
$password = md5($_POST['value']);
and make a function

if (empty($password))
echo "Fields Required"

Its not saying its a false value but true? (wont echo the error)
But when I put

if ($password==true)
echo $password

its echoing A blank md5?

so how can i echo a md5 field out if the user hasnt submited any text??
I have A tempprary solourion but adding md5($password)
on function and leaving it as plain text as a value.

$password = md5($_POST['value']);
if($_POST['value'] == "") echo "Fields Required";
 
@Spork Thanks How about if I wanted to add two or more fields so if i field in $password but $newpass wasnt filled in still this error would still be outputed 😉


And I have created a password change script one minor issue
When i write a else statement it ignoes it? But if i take the else statement out it procceses it succesdfully.


Heres my code (First big code ive written getting better 😉

I know The sql select query is a sql injection prone im going to chànge this once i get thè script working.

Please Tweak This abit to get the else statements in (Been Working Hard Today)


Code:
<?php
session_start();

require "connect.php";

$oldpass = $_POST['oldpass'];
$newpass = $_POST['newpass'];
$compass = $_POST['compass'];

$username = $_SESSION['username'];

//create values as md5 for securiry

$oldpassmd5 = md5($_POST['oldpass']);
$newpassmd5 = md5($_POST['newpass']);
$compassmd5 = md5($_POST['compass']);


$query = mysql_query ("SELECT * FROM users WHERE username='$username'") or die ("SQL Error");

$numrows = (mysql_num_rows($query));

if ($numrows!=0)

while ($row = mysql_fetch_assoc($query))

$dbpassword = $row['password'];







if (empty($oldpass) && empty  ($newpass) && empty ($compass))
die ("You Haven't Filled In The Required Fields");





if ($oldpassmd5==$dbpassword)



if ($compassmd5==$newpassmd5)


$passchange = mysql_query ("UPDATE users SET password='$newpassmd5' WHERE username='$username'") or die ("Error");
if ($passchange==true)
echo "Password Changed";

//otherwise if there not equal (ELSE STATEMENT SHOULD GO HERE)
if ($oldpassmd5!=$dbpassword)
echo "Wrong Password";

?>
<meta name='viewport' name='width'content='width=device-width' </
 
I got the errors outputing by adding else statements with {
}

Wondering if there's a function that will detect both <td> & <br> so if i added a extra space it can detect this.
I look on google tommorow when I get home from work & school (Home now but weekday tomorrow)

Seen it somewhere before but carnt remember where, How do I stop code from being added...
(Except <br> & <td>)

PS: Seen Many sites where the <br> Is hidden but it still does the break sounds relistic
how is that possible?
There my last questions And I can do the rest my self & buy
PHP Books..

Please Reply.

Thanks for the help 😉
 
Back
Top Bottom