Inserting comments via a procedure

Few notes here. 1, why are you re-declaring variables.

For example:

$comment_ID = comment_ID;
$comment_post_ID = comment_post_ID;
$comment_author = comment_author;
$comment_author_email = comment_author_email; 

Is all pointless, If a variable is set already, no reason to set it a second time.
Secondly, unless you pass variables through to the function through arguments like so:

Function wp_insert_comment($some_var, $some_other var) {
}

wp_insert_comment($some_var, $some_other_var);

then once the function runs, those variables at the beginning will = nothing, as they aren’t set.

Third, it looks like either you’re missing the $ in the second set. If you’re working within a class(OOP) , technically you can get away with this as Php will assume these are constants. However, given your code, I’d suggest the issue here is that those variables aren’t being passed through to the function before hand.

Try adding echo $comment_ID, or any of the other variables, and see if anything shows up. If not, that’s your issue. I suppose another method, if you really don’t want to pass through arguments to the function is to use globals, however that’s really bad practice, and can lead to big nightmares when it comes to debugging.

Personally, I like to pass arguments as arrays, that way they can be changed or new variables added, without having to change every instance of the function call. For example
I’d do something like this:

function some_function ($array=array()) {
// do some stuff 
}

some_function (array('variable_1'=>$variable, 'variable_2'=>$variable_2));

it may be a bit of extra typing, but it’s worth it since you make your functions much more flexible.

To answer your question, the reason your variables seem empty, is because you are addressing the array incorrectly. Assuming that $commentdata is the array passed, you’d address the variables like so:

$comment_ID = $commentdata['comment_ID'];
$comment_post_ID = $commentdata['comment_post_ID'];

etc etc. This is because, an array stores data in something called a key=>value pair. Try doing:

var_dump($commentdata);

right at the beginning of your function call, to get a better understanding of what I mean.

As it seems you’re relatively new to php, I’d suggest utilizing the following resources, to make the learning a bit easier:

http://www.php.net/ or
http://www.w3schools.com/PHP/

or take a look at some of the questions and answers in the php section of SO.