I don't understand why your using a class to do that, but whatever floats your boat. I am not a pro at classes, so if this is wrong then someone please correct me. I haven't written many classes, but this one should work.. I didn't test it but I did create a mysql table to see if it connected, and it did so it should work.
comments.inc.php
PHP Code:
<?php
include("http://wghq.net/config.php");
class Comment {
var $table;
var $nick;
var $post;
var $date;
var $id;
var $date;
var $time;
function table($table) {
$this->table=trim(addslashes($table));
}
function submit_data($data) {
$this->nick=addslashes($data['nick']);
$this->date=$data['date'];
$this->time=$data['time'];
$this->id=$data['id'];
$this->post=addslashes($data['post']);
}
function add_Comment(){
if(!$this->post){
return false;
}else{
If(!mysql_query("INSERT INTO ".$this->table." VALUES('null','".$this->id."','".$this->nick."','".$this->post."','".$this->date."','".$this->time."'")) {
return false;
}
echo'Added';
return true;
}
}
function read_Comments($id){
$display_comments = mysql_query("SELECT * FROM ".$this->table." WHERE id='".intval($id)."'");
while($comments = mysql_fetch_array($display_comments)){
$nickname_ = $comments['nick'];
$date_ = $comments['date'];
$post_ = $comments['post'];
$time_ = $comments['time'];
echo' <table border="0" cellpadding="4" cellspacing="0" style="border-collapse: collapse; font-size:10px; font-family:Arial" bordercolor="#111111" width="100%" id="AutoNumber2">
<tr>
<td width="100%">
<table border="1" style="border-collapse: collapse; font-size: 10px; font-family: Arial" bordercolor="#800000" width="100%" id="AutoNumber3">
<tr>
<td width="100%">Posted By:'.$nickname_.' :: Posted on '.$date_.', at '.$time_.'</td>
</tr>
<tr>
<td width="100%">'.$post_.'</td>
</tr>
</table>
</td>
</tr>
</table>
';
}
}
}
?>
comments.php
PHP Code:
<?php
include("main_inc/comments.inc.php");
if($post != "yes"){
$comment_class = new Comment;
$comment_class->table("newscomments");
$read_comment=$comment_class->read_Comments($id);
print($read_comment);
}else{
if($_POST['submit']){
$comment_class = new Comment;
$comment_class->table("newscomments");
$submit_data=array(
'table' => "newscomments",
'nick' => $_POST['nick'],
'date' => date("m/d/Y"),
'time' => date("h:i:s A"),
'id' => $_GET['id'],
'post' => $_POST['post']
);
$comment_class->submit_data($submit_data);
if(!$comment_class->add_Comment()){
echo'Cannot add your comment, please try again!';
}else{
echo'Thank you for posting your comment...please refresh this page by clicking <a href="comments.php?pg='.$_GET['$pg'].'&id='.$id.'">here</a>';
}
}else{
echo' <form method="POST" action="comment.php?pg='.$_GET['pg'].'&id='.$_GET['id'].'&post=yes">
<table border="0" cellpadding="4" cellspacing="0" style="border-collapse: collapse; font-size:10px; font-family:Arial" bordercolor="#111111" width="100%" id="AutoNumber2">
<tr>
<td width="100%">
<table border="1" cellspacing="0" style="border-collapse: collapse; font-size: 10px; font-family: Arial; color: #800000; border-style: solid; border-width: 1" bordercolor="#800000" width="100%" id="AutoNumber3" height="22">
<tr>
<td width="50%" height="13">Nick Name:</td>
<td width="50%" height="13">
<input type="text" name="nick" size="122" style="font-size: 10px; font-family: Arial; color: #800000; border-style: solid; border-width: 1"></td>
</tr>
<tr>
<td width="50%" height="8">Comment:</td>
<td width="50%" height="8">
<textarea rows="12" name="post" cols="59" style="color: #800000; border-style: solid; border-width: 1"></textarea></td>
</tr>
<tr>
<td width="50%" height="8">Submit:</td>
<td width="50%" height="8">
<p align="center">
<input type="submit" value="Submit" name="submit" style="font-size: 10px; font-family: Arial; color: #800000; border-style: solid; border-width: 1"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
';
}
}
?>