Viewing Topic: Help! Comment
script. |
gilrok |
Subject: "Help! Comment
script."
Posted: @ 6:57 am on Jun 24 2008 |
|
|
Member #: 708 Rank: user - (3) Since: 06/24/08 Posts: 3
|
Hey, thanks for
the awesome
comments
script! I've
added it to my
site, connected
to my data base
etc etc. But
there is one
thing wrong! No
comments disply
when added! Not
even any
errors, do i'm
miffed at what
i've done
wrong!
Code:
<?
//connect to
your
database
mysql_connect(
"localhost
",
"gilrok_Gi
lrok",
"BUHUFXQE&
quot;);
mysql_select_d
b("gilrok_
useraccounts&qu
ot;);
//query
comments for
this page of
this article
$inf =
"SELECT *
FROM `comments`
WHERE page =
'".stripsl
ashes($_SERVER[
'REQUEST_URI'])
."' ORDER
BY time
ASC";
$info =
mysql_query($in
f);
if(!$info)
die(mysql_error
());
$info_rows =
mysql_num_rows(
$info);
if($info_rows
> 0) {
echo
'<h5>Comm
ents:</h5>
;';
echo
'<table
width="95%
">';
while($info2 =
mysql_fetch_obj
ect($info)) {
echo
'<tr>';
echo
'<td>&quo
t;'.stripslashe
s($info2->su
bject).'"
by: <a
href="'.$i
nfo2->contac
t.'">'.
stripslashes($i
nfo2->userna
me).'</a>
</td>
<td><d
iv
align="rig
ht"> @
'.date('h:i:s
a',
$info2->time
).' on
'.$info2->da
te.'</div>
;</td>';<
br />
echo
'</tr><
;tr>';
echo '<td
colspan="2
">
'.stripslashes(
$info2->comm
ent).'
</td>';
echo
'</tr>';<
br />
}//end while
echo
'</table>
';
echo '<hr
width="95%
"
noshade>';
} else echo 'No
comments for
this page. Feel
free to be the
first
<br>';
if(isset($_POST
['submit']))
{
if(!addslashes(
$_POST['usernam
e']))
die('<u>E
RROR:</u>
you must enter
a username to
add a
comment.');
if(!addslashes(
$_POST['contact
']))
die('<u>E
RROR:</u>
enter contact
method in
contact
field.');
if(!addslashes(
$_POST['subject
']))
die('<u>E
RROR:</u>
enter a subject
to your
comment.');
if(!addslashes(
$_POST['comment
']))
die('<u>E
RROR:</u>
cannot add
comment if you
do not enter
one!?');
//this is for a
valid
contact
if(substr($_POS
T['contact'],0,
7) != 'mailto:'
&&
!strstr($_POST[
'contact'],'//'
)) {
if(strstr($_POS
T['contact'],'@
'))
$_POST['contact
'] =
"mailto:&q
uot;.$_POST['co
ntact']."&
quot;;
else
$_POST['contact
'] =
"http://&q
uot;.$_POST['co
ntact']."&
quot;;
} //end
valid
contact
//try to
prevent
multiple posts
and
flooding...
$c =
"SELECT *
from `comments`
WHERE ip =
'".$_SERVE
R['REMOTE_ADDR'
]."'"
;
$c2 =
mysql_query($c)
;
while($c3
=
mysql_fetch_obj
ect($c2)) {
$difference =
time() -
$c3->time;
if($difference
< 300)
die('<u>A
LERT:</u>
'.$c3->usern
ame.', You have
already
commented
earlier; if you
have a
question, try
the
forums!<BR&g
t;');
} //end
while
//add
comment
$q
="INSERT
INTO `comments`
(article_id,
page, date,
time, username,
ip, contact,
subject,
comment) VALUES
('".$_GET[
'id']."',
'".$_POST[
'page']."'
,
'".$_POST[
'date']."'
,
'".$_POST[
'time']."'
,
'".addslas
hes(htmlspecial
chars($_POST['u
sername'])).&qu
ot;',
'".$_SERVE
R['REMOTE_ADDR'
]."',
'".addslas
hes(htmlspecial
chars($_POST['c
ontact'])).&quo
t;',
'".addslas
hes(htmlspecial
chars($_POST['s
ubject'])).&quo
t;',
'".addslas
hes(htmlspecial
chars(nl2br($_P
OST['comment'])
))."')&quo
t;;
$q2 =
mysql_query($q)
;
if(!$q2)
die(mysql_error
());
//refresh page
so they can see
new comment
header('Locatio
n: http://' .
$_SERVER['HTTP_
HOST'] .
$_POST['page']
.
"#comments
");
} else {
//display
form
?>
<form
name="comm
ents"
action="&l
t;?
$_SERVER['PHP_S
ELF'];
?>"
method="po
st">
<input
type="hidd
en"
name="page
"
value="<
;?
echo($_SERVER['
REQUEST_URI']);
?>">
<input
type="hidd
en"
name="date
"
value="<
;?
echo(date("
;F j,
Y."));
?>">
<input
type="hidd
en"
name="time
"
value="<
;?
echo(time());
?>">
<table
width="90%
"
border="0&
quot;
cellspacing=&qu
ot;0"
cellpadding=&qu
ot;0"><
br />
<tr>
<td><d
iv
align="rig
ht">Use
rname:
</div><
;/td>
<td><i
nput
name="user
name"
type="text
"
size="30&q
uot;
value="&qu
ot;></td&
gt;
</tr>
<tr>
<td><d
iv
align="rig
ht">Con
tact:
</div><
;/td>
<td><i
nput
type="text
"
name="cont
act"
size="30&q
uot;
value="&qu
ot;>
<i>(email
or
url)</i>&
lt;/td>
</tr>
<td><d
iv
align="rig
ht">Sub
ject:
</div><
;/td>
<td><i
nput
type="text
"
name="subj
ect"
size="30&q
uot;
value="&qu
ot;></td&
gt;
</tr>
<tr>
<td><d
iv
align="rig
ht">Com
ment:
</div><
;/td>
<td><t
extarea
name="comm
ent"
cols="45&q
uot;
rows="5&qu
ot;
wrap="VIRT
UAL">&l
t;/textarea>
</td>
</tr>
<tr>
<td></
td>
<td
colspan="2
"><i
nput
type="rese
t"
value="Res
et
Fields">
;
<input
type="subm
it"
name="subm
it"
value="Add
Comment"&g
t;</td>
</tr>
</table><
br />
</form>
<?
} // end
else
?>
I hope you can
help! :)
Thanks!
|
Viewed: 12,979 Times | |  |
bs0d |
Subject: "re: Help!
Comment script."
Posted: @ 10:43 pm on Jun 24 2008
|
|
|
 Member #: 1 Rank: Admin. - (1,510) Since: 02/06/05 Posts: 604 From: USA
|
Check the URL
in the database
for the
comment. Make
sure that the
URL you visit
(to see the
comment) is
exactly as
shown in the
database. This
maybe case
sensitive as
well.
|
Viewed: 12,967 Times | |  |
gilrok |
Subject: "re: Help!
Comment script."
Posted: @ 7:18 am on Jun 25 2008
|
|
|
Member #: 708 Rank: user - (3) Since: 06/24/08 Posts: 3
|
Sorry, i'm new
to a lot of
this, were
would i find my
database URL?
I'm using
PHPmyAdmin
|
Viewed: 12,962 Times | |  |
bs0d |
Subject: "re: Help!
Comment script."
Posted: @ 10:21 pm on Jun 25 2008
|
|
|
 Member #: 1 Rank: Admin. - (1,510) Since: 02/06/05 Posts: 604 From: USA
|
it's the
'page' column
of your
'comments'
table (in
phpMyAdmin).
|
Viewed: 12,950 Times | |  |
gilrok |
Subject: "re: Help!
Comment script."
Posted: @ 2:44 pm on Jun 26 2008
|
|
|
Member #: 708 Rank: user - (3) Since: 06/24/08 Posts: 3
|
I can't
find anything
to do with a
URL in the Page
column, sorry.
could you give
me a few more
details on what
i'm looking
for?
thanks again
Edited at 02:46:37 pm on 06/26/08
|
Viewed: 12,937 Times | |  |
Genius |
Subject: "re: Help!
Comment script."
Posted: @ 2:57 pm on Jun 26 2008
|
|
|
 Member #: 582 Rank: user - (77) Since: 02/18/08 Posts: 76 From: kmmk
|
Umm did
you run the sql
first? So those
tables/columns
would be there
to store info.
Ok here:
Code:
CREATE TABLE
`comments` (
`article_id`
int(11) NOT
NULL default
'0',
`id` int(11)
NOT NULL
auto_increment,
`page`
varchar(255)
NOT NULL
default '',
`username`
varchar(255)
NOT NULL
default
'Guest',
`subject`
varchar(255)
NOT NULL
default '',
`contact`
varchar(255)
NOT NULL
default '',
`comment`
text NOT NULL,
`ip`
varchar(15) NOT
NULL default
'0',
`date`
varchar(255)
NOT NULL
default '',
`time`
varchar(11) NOT
NULL default
'',
PRIMARY KEY
(`id`)
) TYPE=MyISAM
AUTO_INCREMENT=
51
;
I've never
tried this
script so I
wouldn't know
anything about
it.
Edited at 03:06:58 pm on 06/26/08
|
Viewed: 12,932 Times | |  |
bs0d |
Subject: "re: Help!
Comment script."
Posted: @ 10:44 pm on Jun 26 2008
|
|
|
 Member #: 1 Rank: Admin. - (1,510) Since: 02/06/05 Posts: 604 From: USA
|
Yes, that SQL
code will
create the
table with the
colmns defined.
If the script
is indeed
adding a
comment (it may
not be), then
you should see
it as a row for
the comments
table.
try to echo
variables
through the
script that are
benchmarks that
identify
portions of
code that are
complete. Then
you can see if
you have a
logical error
in the code
(executes, but
not the desired
output).
|
Viewed: 12,914 Times | |  |
Viewing Page: 1 of 1 |
|