0)
post_comment($page_id);
break;
case "get_form":
get_comments($page_id);
echo '
';
break;
case "get_comments":
$comments = get_comments($page_id);
foreach($comments as $comment) {
$mine = ($comment->IP == $_SERVER['REMOTE_ADDR']) ? " mine" : "";
echo "\r";
}
break;
default:
print_r($_POST);
break;
}
function post_comment($page_id){
global $db;
$query = "INSERT INTO comments (page_id, timestamp, user, comment, IP) VALUES ('%s',NOW(),'%s','%s', '%s')";
if (!isset($_POST['username'])) { echo print_r($_POST); return -1; }
$db->safe_query($query, $page_id, $_POST['username'], $_POST['comment'], $_POST['IP']);
// echo $query;
}
function get_comments($page_id){
global $db;
$query = "
SELECT *
FROM comments
WHERE page_id='" . $page_id . "'
ORDER BY timestamp";
$db->query($query);
$output = array();
while ($res = $db->fetch_object()) {
array_push($output, $res);
}
return $output;
}
?>
$comment->user ($comment->IP) says:
\r$comment->comment\r" . date("D, F jS y g:i:s a", strtotime($comment->timestamp)) . "\r