TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-19-2009, 09:45 AM   #1 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 15
Thanks: 11
tearsofthesun is on a distinguished road
Default Comments on each page??

Hi, can someone point me in the right direction. i have searched all over the net and there isn't one single one that i am looking for.

I wanted to have a comment box on each of my pages so users can comment that page. i have tons of page in my website that contains urls that end with id=45 and etc.

ex: if user comment pages id=45

i don't want the comments on page id=45 to appear on id=46

thanks!
tearsofthesun is offline  
Reply With Quote
Old 08-19-2009, 10:09 AM   #2 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

In your table for the comments, use a row for pageId that stores the ID of the page the comment is associated with. Then on the page, you just fetch the comments with pageId = $_GET['id']. Remember to secure that for sql injections.
__________________
Tanax is offline  
Reply With Quote
The Following User Says Thank You to Tanax For This Useful Post:
tearsofthesun (08-19-2009)
Old 08-19-2009, 10:48 AM   #3 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 15
Thanks: 11
tearsofthesun is on a distinguished road
Default

Here's my code for it, but i don't know where to place that ID_ code you gave me.

PHP Code:
<?php
//Connect to database
include ('connect1.php');
$queryget mysql_query("SELECT* FROM comments");
while (
$row mysql_fetch_assoc($queryget))
{
//get row data and store in var's
$id $row['id'];
$name $row['name'];
$email $row['email'];
$message $row['message'];
$date $row['date'];
$time $row['time'];
 
 
//show data to user
echo"<table><tr><td>
Posted by: <b>
$name ($email) on $date</b>
</td></tr><tr>

<td>"
.strip_tags($message)."</td></tr></table>";
}

echo 
"<hr>";

if (
$_POST['submit'])
{
$name $_POST['name'];
$email $_POST['email'];
$message $_POST['message'];
$date date ("m-d-Y");
$time date ("H:i:s");

if(
$name&&$message)
{
$querypost mysql_query ("INSERT INTO comments VALUES ('','$name','$email','$message','$date','$time')");
echo
"Please wait..... <meta http-equiv='refresh' content='1;url=results3.php?id=$id'>";
}
else
echo 
"Please fill out all fields.";
}

echo 
"<form action='results3.php?id=$id' method='POST'><table width='100%'>
<tr><td width='5%' valign='top'>Name:</td>
<td><input type='text' name='name' maxlength='25'></td></tr>

<tr><td valign='top'>Email:</td><td><input type='text' name='name' maxlength='25'></td></tr>

<tr><td valign='top'>Message:</td><td>
<textarea cols='20' rows='2' name='message' maxlength='250'></textarea>
<p>
<input type='submit' name='submit' value='Post'>
</td>
</tr>
</table>
</form>"
;
?>
tearsofthesun is offline  
Reply With Quote
Old 08-19-2009, 12:08 PM   #4 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 11
Thanks: 1
jasonberresford is on a distinguished road
Default

Here's my quick edit:



Code:
<?php
//Connect to database
include ('connect1.php');
$pageid = $_GET['id'];
$queryget = mysql_query("SELECT* FROM comments WHERE pageid = '$pageid'");
while ($row = mysql_fetch_assoc($queryget))
{
//get row data and store in var's
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$message = $row['message'];
$date = $row['date'];
$time = $row['time'];
 
 //show data to user
echo"<table><tr><td>
Posted by: <b>$name ($email) on $date</b>
</td></tr><tr>

<td>".strip_tags($message)."</td></tr></table>";
}

echo "<hr>";

if ($_POST['submit'])
{

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$date = date ("m-d-Y");
$time = date ("H:i:s");

if($name&&$message)
{
$querypost = mysql_query ("INSERT INTO comments VALUES ('','$name','$email','$message','$date','$time','$pageid')");
echo"Please wait..... <meta http-equiv='refresh' content='1;url=results3.php?id=$id'>";
}
else
echo "Please fill out all fields.";
}

echo "<form action='results3.php?id=$id' method='POST'><table width='100%'>
<tr><td width='5%' valign='top'>Name:</td>
<td><input type='text' name='name' maxlength='25'></td></tr>

<tr><td valign='top'>Email:</td><td><input type='text' name='name' maxlength='25'></td></tr>

<tr><td valign='top'>Message:</td><td>
<textarea cols='20' rows='2' name='message' maxlength='250'></textarea>
<p>
<input type='submit' name='submit' value='Post'>
</td>
</tr>
</table>
</form>";
?>
Something like that .. Grab the id at the start, when you do an insert insert with the ID, and when you do the select for the page grab the ID .. nothing to it :)
jasonberresford is offline  
Reply With Quote
The Following User Says Thank You to jasonberresford For This Useful Post:
tearsofthesun (08-19-2009)
Old 08-20-2009, 02:09 PM   #5 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 15
Thanks: 11
tearsofthesun is on a distinguished road
Default

Still not working :(

Here is an example:
http://www.starcraftx.com/results.ph...ame=gravedigga

I type in a comment for that user,

but the same comment i type in for that user show's up in every other page...

http://www.starcraftx.com/results.php?setname=DoS.E
http://www.starcraftx.com/results.php?setname=Im.Back

PHP Code:
<?php
//Connect to database
include ('connect1.php');
$id $_GET['id'];
$queryget mysql_query("SELECT * FROM comments");
while (
$row mysql_fetch_assoc($queryget))
{
//get row data and store in var's
$id $row['id'];
$name $row['name'];
$email $row['email'];
$message $row['message'];
$date $row['date'];
$time $row['time'];
 
 
//show data to user
echo"
<table width='100%'><tr>

<td background='images/anynav3.gif'>"
.$name." <br> ".$message."</td></tr></table>";
}

if (
$_POST['submit'])
{

$name $_POST['name'];
$email $_POST['email'];
$message $_POST['message'];

if(
$name&&$message)
{
$querypost mysql_query ("INSERT INTO comments VALUES ('','$name','$email','$message','$date','$time')");
echo
"Please wait..... <meta http-equiv='refresh' content='1;url=results.php?setname=$setname'>";
}
else
echo 
"Please fill out all fields.";
}

echo 
"
<form action='results.php?setname=
$setname' method='POST'><table width='100%'>

<input type='hidden' readonly='readonly' name='name' size='20' value='
$_SESSION[user]'>

<textarea cols='20' rows='2' name='message' maxlength='250'>
</textarea>

<input type='submit' name='submit' value='Post'>
</td>
</tr>
</table>
</form>"
;
?>
tearsofthesun is offline  
Reply With Quote
Old 08-20-2009, 02:13 PM   #6 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 11
Thanks: 1
jasonberresford is on a distinguished road
Default

Yep your missing one thing:

$id = $_GET['id'];
$queryget = mysql_query("SELECT * FROM comments");

CHANGE TO:

$id = $_GET['id'];
$queryget = mysql_query("SELECT * FROM comments WHERE id = '$id'");

That will make sure it only selects that comments ...

Not every comment which loops through and just outputs the last on all pages.
jasonberresford is offline  
Reply With Quote
The Following User Says Thank You to jasonberresford For This Useful Post:
tearsofthesun (08-20-2009)
Old 08-20-2009, 02:21 PM   #7 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 11
Thanks: 1
jasonberresford is on a distinguished road
Default

Yeah looks like your missing a few other things as well.

When you insert the comment you need to insert it with an ID of the page .. So that you can call them all later on.

Using Int is normally better then using Text or Varchar matching. (Faster)

The code I typed originally had some other changes .. (on the insert statement)
jasonberresford is offline  
Reply With Quote
The Following User Says Thank You to jasonberresford For This Useful Post:
tearsofthesun (08-20-2009)
Old 08-20-2009, 02:46 PM   #8 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 15
Thanks: 11
tearsofthesun is on a distinguished road
Default

well, when i entered

PHP Code:
$id $_GET['id'];
$queryget mysql_query("SELECT * FROM comments WHERE id = '$id'"); 
the comments now doesn't display. but if i take out the
PHP Code:
id '$id' 
it does. kinda weird and i've been working on this since yesterday lol :(
tearsofthesun is offline  
Reply With Quote
Old 08-20-2009, 02:59 PM   #9 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 11
Thanks: 1
jasonberresford is on a distinguished road
Default

Well yes ... id needs to be passed in the url for it to work, and needs to be stored in the database when you create the comment.

Basically you need to tie everything together,

When the comment is added you need to insert an identifier of the page .. Normally I just us an ID # for speed..

Then when you select the page .. you select the comment records with that same ID number...

Seeing as you are already passing: setname=DoS.E

It might be easier to change things slightly, when adding the comment add in the setname as the unique identifier in the comments db .. then when you select ... select by setname ..

Clear as mud? :)

The main reason i'm trying to push to ID is because if the site gets larger and the DB for comments gets large you want to have an INT field not TEXT/VAR for the joinning.
jasonberresford is offline  
Reply With Quote
The Following User Says Thank You to jasonberresford For This Useful Post:
tearsofthesun (08-20-2009)
Old 08-30-2009, 08:54 AM   #10 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 15
Thanks: 11
tearsofthesun is on a distinguished road
Default

Well i sort of got this script to work, alright here is the problem.

When i go to MY ADMIN PHP and manually insert some dummie data's it works. but when i go to a user's page and type in some comments, it doesn't display.

you can try it here,
http://www.starcraftx.com/results.php?id=103

anyone seem to know whats wrong??? thanks!

PHP Code:
<?php
//Connect to database
include ('connect.php');
$id $_GET['id'];
$queryget mysql_query("SELECT * FROM members WHERE id = '" $id "' ") or die (mysql_error());
$row mysql_fetch_array($queryget);
{
//get row data and store in var's
$id $row['id'];
$name $row['name'];
$message $row['message'];

//show data to user
echo"
<table><tr>

<td>"
.$message." <br> ".$setname."</td></tr></table>";
}

if (
$_POST['submit'])
{
$name $_POST['name'];
$message $_POST['message'];

if(
$name&&$message)
{
$querypost mysql_query ("INSERT INTO members VALUES ('','$name','$message')");
echo
"Please wait..... <meta http-equiv='refresh' content='1;url=results.php?id=$id'>";
}
else
echo 
"Please fill out all fields.";
}

echo 
"
<form action='results.php?id=
$id' method='POST'><table width='100%'>
<tr><td width='5%' valign='top'>Name:</td>
<td><input type='text' name='name' maxlength='25'></td></tr>

<tr><td valign='top'>Message:</td><td>
<textarea cols='20' rows='2' name='message' maxlength='250'></textarea>
<p>
<input type='submit' name='submit' value='Post'>
</td>
</tr>
</table>
</form>"
;
?>
tearsofthesun is offline  
Reply With Quote
Old 08-30-2009, 11:25 AM   #11 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

Your insert query doesn't insert the id of the page together, that's why you can't link the specific comment to the page. Try something like

Code:
INSERT INTO members VALUES ($id, '$name', '$message')
I wouldn't do this if I were you, it's better to create a new column to specify which page the comment belongs to like page_id or something like that.
TheOnly92 is offline  
Reply With Quote
The Following User Says Thank You to TheOnly92 For This Useful Post:
tearsofthesun (08-30-2009)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
help on making my own crawler webtuto General 16 08-08-2009 08:55 AM
Execute a script and call that file in an HTML page j4v1 General 2 05-22-2008 01:41 PM
Page Load Count Wildhoney Script Giveaway 1 03-25-2008 04:48 AM
Extracting page titles and placing into dropdown box. Dorza General 6 10-29-2007 11:01 PM


All times are GMT. The time now is 06:58 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design