<?php
//include("fn_auth.php");
//session_start();
//$authenticatedUser = $HTTP_SESSION_VARS["authenticatedUser"];
$user_id $HTTP_POST_VARS["user_id"];
$post_id $HTTP_POST_VARS["post_id"];
$auth $HTTP_POST_VARS["auth"];
$name $HTTP_POST_VARS["name"];
$url $HTTP_POST_VARS["url"];
$comment $HTTP_POST_VARS["comment"];

// encode and escape text before entry into the database
$name mysql_escape_string($name);
$comment mysql_escape_string($comment);
//$title = urlencode($title);
//$content = urlencode($content);

// connect to db
$connection mysql_connect("localhost""user""pass");
mysql_select_db("main"$connection) or die("No db");

$timestamp date('Y-m-d H:i:s');

// update comment in db
$query "INSERT INTO comments VALUES
          (NULL, '" 
$post_id "', '" $timestamp "', '" $name "', '"
          
$url "', '" $comment "')";
$result mysql_query($query) or die("Query failed : " mysql_error());

// also need to increment the num_comments field in posts table here
$query_get "SELECT datetime, num_comments from posts where post_id=$post_id";
$result_get mysql_query($query_get) or die("get query failed");
//$row_get = mysql_fetch_array($result_get);
while ($row_get mysql_fetch_array($result_get)) {
$timestamp $row_get[0];

}



$query_update "UPDATE posts SET datetime=$timestamp, num_comments = num_comments+1 where post_id=$post_id";
$result_update mysql_query($query_update) or die("update Query failed : " mysql_error()); 

header("Location: ./comments.php?user_id=$user_id&auth=$auth&post_id=$post_id");

?>