Location: PHPKode > projects > ProjectPress > projectpress/projects/forum/preply.php
<?php
/**
 * ProjectPress project forum reply
 *
 * @package ProjectPress
 * @since 2.0
 */

// Starts the session.
session_start();

define('access',true);
include(dirname(dirname(dirname(__FILE__))) . '/config.inc.php');
include(PM_DIR . 'pm-includes/global.inc.php');

if($current_user->hasPermission('access_site') != true) { pm_redirect(PM_URI . '/index.php'); }

// Enable for error checking and troubleshooting.
# display_errors();

// Get value of id that sent from hidden field 
$id = $_POST['id'];

// Find highest answer number. 
$sql = "SELECT MAX(p_id) AS Maxp_id FROM " . DB . "project_forum_posts WHERE topic_id='$id' AND pp_id = '".$_GET['p_id']."'";
$result = pmdb::connect()->query($sql);
$rows = $result->fetch_object();

// add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 
if ($rows) {
$Max_id = $rows->Maxp_id+1;
} else {
$Max_id = 1;
}

// get values that sent from form 
$username = $_SESSION['username'];
$pfp_post = $_POST['pfp_post']; 
$pfp_datetime = date("y-m-d H:i:s"); // create date and time 

// Insert post
if ($pfp_post == "") { // Checks for blanks.
		exit("There was a field missing, please correct the form.");
	} else { 
$sql2 = "INSERT INTO " . DB . "project_forum_posts(topic_id, pp_id, pfp_user, pfp_post, pfp_datetime)VALUES('$id', '".$_GET['p_id']."', '$username', '$pfp_post', '$pfp_datetime')";
$result2 = pmdb::connect()->query($sql2);
}

if($result2){
header('Location: view_ptopic.php?p_id='.$_GET['p_id'].'&id='.$id.'');

// If added new post, add value +1 in reply column 
if ($pfp_post == "") { // Checks for blanks.
		exit("There was a field missing, please correct the form.");
	} else {
$sql3 = "UPDATE " . DB . "project_forum_topics SET pft_reply = '$Max_id' WHERE pft_id = '$id' AND pt_id = '".$_GET['p_id']."'";
$result3 = pmdb::connect()->query($sql3);
	}
} else {
echo "ERROR";
}
Return current item: ProjectPress