使用选择查询插入查询

I want to select category id, category name, category type, average of rate columns in review table and i want to save it result table category id, category name, category type, average of rate in automatically. so i tried below code. but it didn't work. so if you have any solution please help me to fix this? or if have another method to accomplish my task can you please describe it. help me to fix this error to quickly. I want to select category id, category name, category type, average of rate columns in review table and i want to save it result table category id, category name, category type, average of rate in automatically. so i tried below code. but it didn't work. so if you have any solution please help me to fix this? or if have another method to accomplish my task can you please describe it. help me to fix this error to quickly.

<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("testing",$con);
function setReviews($con){
    if (isset($_POST['submit'])) {
        $user_email=$_POST["user_email"];
        $user_name=$_POST["user_name"];
        $review=$_POST["review"];
        $rate=$_POST["rate"];
        $sql=mysql_query("SELECT user_email FROM review WHERE user_email='$user_email'");
        if (mysql_num_rows($sql)>0) {
            echo "user mail already exist";
        }else{
            mysql_query("INSERT INTO review(user_email,user_name,rate,review) VALUES ('$user_email','$user_name','$rate','$review')");
        echo "submitted";
        }
    }
} 
function getratingsave($con){
    $category_id=1;
        $sql="INSERT INTO result (category_id,cat_name,cat_type,t_rate) SELECT category_id,AVG(rate),cat_name,cat_type FROM review WHERE category_id='$category_id'";
        $result=mysql_query($sql,$con);
}
?>

1st : Miss matched order of column and values

 $sql="INSERT INTO result (category_id,cat_name,cat_type,t_rate) SELECT category_id,AVG(rate),cat_name,cat_type FROM review WHERE category_id='$category_id'";

Note : Specified column order should be matched with value order.

To

 $sql="INSERT INTO result (category_id,cat_name,cat_type,t_rate) SELECT category_id,cat_name,cat_type,AVG(rate) FROM review WHERE category_id='$category_id'";

2nd : Mysql is deprecated try to use mysqli or PDO.

3rd : And also try to use prepared statement.