<
i>
bs0d
said... [=
Make sure you
connect to the
database
first.
Yeah I did
that, here is
my code.
<BR><f
ont
size=1><u
>Code:</u
><BR>&
lt;div
name="div
_box"
class="di
vCode">
; <?
//connect to
your database
require_once('
connection.php
');
//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>Com
ments:</h5&g
t;';
echo
'<table
width="95
%">';
while($info2 =
mysql_fetch_obj
ect($info)) {
echo
'<tr>';
echo
'<td>&q
uot;'.stripsla
shes($info2->
;subject).'&q
uot; by: <a
href="'.
$info2->cont
act.'"&g
t;'.stripslash
es($info2->u
sername).'<
/a></td&g
t;
<td><d
iv
align="ri
ght">
@
'.date('h:i:s
a',
$info2->time
).' on
'.$info2->d
ate.'</div&
gt;</td>
';
echo
'</tr>&l
t;tr>';
echo '<td
colspan="
2">
'.stripslashes
($info2->com
ment).'
</td>';
echo
'</tr>'
;
}//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['userna
me']))
die('<u>
ERROR:</u>
; you must
enter a
username to add
a comment.');
if(!addslashes(
$_POST['contac
t']))
die('<u>
ERROR:</u>
; enter contact
method in
contact
field.');
if(!addslashes(
$_POST['subjec
t']))
die('<u>
ERROR:</u>
; enter a
subject to your
comment.');
if(!addslashes(
$_POST['commen
t']))
die('<u>
ERROR:</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['contac
t'] =
"mailto:
".$_POST[
'contact'].&q
uot;";
else
$_POST['contac
t'] =
"http://
".$_POST[
'contact'].&q
uot;";
} //end
valid contact
//try to
prevent
multiple posts
and flooding...
$c =
"SELECT *
from `comments`
WHERE ip =
'".$_SER
VER['REMOTE_AD
DR']."'
";
$c2 =
mysql_query($c)
;
while($c3
=
mysql_fetch_obj
ect($c2)) {
$difference =
time() -
$c3->time;
if($difference
< 300)
die('<u>
ALERT:</u>
;
'.$c3->user
name.', 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
('".$_GE
T['id'].&quo
t;',
'".$_POS
T['page'].&q
uot;',
'".$_POS
T['date'].&q
uot;',
'".$_POS
T['time'].&q
uot;',
'".addsl
ashes(htmlspeci
alchars($_POST[
'username']))
."',
'".$_SER
VER['REMOTE_AD
DR']."'
,
'".addsl
ashes(htmlspeci
alchars($_POST[
'contact'])).
"',
'".addsl
ashes(htmlspeci
alchars($_POST[
'subject'])).
"',
'".addsl
ashes(htmlspeci
alchars(nl2br($
_POST['comment
'])))."
')";
$q2 =
mysql_query($q)
;
if(!$q2)
die(mysql_error
());
//refresh page
so they can see
new comment
header('Locati
on: http://' .
$_SERVER['HTTP
_HOST'] .
$_POST['page'
] .
"#comment
s"

;
} else {
//display form
?>
<form
name="com
ments"
action="&
lt;?
$_SERVER['PHP_
SELF'];
?>"
method="p
ost">
<input
type="hid
den"
name="pag
e"
value="&l
t;?
echo($_SERVER[
'REQUEST_URI']
);
?>">
;
<input
type="hid
den"
name="dat
e"
value="&l
t;?
echo(date(&quo
t;F j,
Y."

);
?>">
;
<input
type="hid
den"
name="tim
e"
value="&l
t;?
echo(time());
?>">
;
<table
width="90
%"
border="0
"
cellspacing=&q
uot;0"
cellpadding=&q
uot;0">
;
<tr>
<td><d
iv
align="ri
ght">U
sername:
</div><
;/td>
<td><i
nput
name="use
rname"
type="tex
t"
size="30
"
value="&
quot;></t
d>
</tr>
<tr>
<td><d
iv
align="ri
ght">C
ontact:
</div><
;/td>
<td><i
nput
type="tex
t"
name="con
tact"
size="30
"
value="&
quot;>
<i>(email
or
url)</i>&
lt;/td>
</tr>
<td><d
iv
align="ri
ght">S
ubject:
</div><
;/td>
<td><i
nput
type="tex
t"
name="sub
ject"
size="30
"
value="&
quot;></t
d>
</tr>
<tr>
<td><d
iv
align="ri
ght">C
omment:
</div><
;/td>
<td><t
extarea
name="com
ment"
cols="45
"
rows="5&
quot;
wrap="VIR
TUAL">
</textarea&g
t;</td>
</tr>
<tr>
<td></
td>
<td
colspan="
2"><
;input
type="res
et"
value="Re
set
Fields"&g
t;
<input
type="sub
mit"
name="sub
mit"
value="Ad
d
Comment"&
gt;</td>
</tr>
</table>
</form>
<?
} // end else
?>
Can no-one help
me sort this
really simple
question, some
people must
have the
comments code
working fine?