<?php

include '../db_connect.php';

$userid = $_POST[ 'userid' ];
$postid = $_POST[ 'postid' ];
$comment = $_POST[ 'comment' ];
$time = $_POST[ 'time' ];
$profile = $_POST[ 'profile' ];
$name = $_POST[ 'name' ];
$key = $_POST[ 'key' ];

$security_key = decrypData( $key );

if ( $security_key == 'Jobayer121415' ) {

    $response = array();

    $con = dbConnect();

    $sql = "INSERT INTO comment_table (userid, postid, comment, time, name, profile) 
            VALUES ('$userid', '$postid', '$comment', '$time', '$name', '$profile')";
            
    $result = mysqli_query ( $con, $sql );

    if ( $result ) {
        echo 'Successfully';
    } else {
        echo'Qury Error';
    }

    echo json_encode( $response );

}

function decrypData( $text ) {
    $encoded = $text;
    $decoded = base64_decode( $encoded );
    $decrypted = openssl_decrypt( $decoded, 'AES-128-ECB', '0175526800812345', OPENSSL_RAW_DATA );
    return $decrypted;
}

?>