Q:

PHP inserting image and video into one mysql record

I am successfully able to insert an image and video file to my mysql database, but it is creating 2 records.  My belief is because of my "Type" field, it's not able to create 2 different values for the same record, so I created "Type" and "Type2" thinking that would solve the issue.  It created the same "Image/png" value.
Here is my form script:
<form action="saveimage.php" enctype="multipart/form-data" method="post">
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5"      cellpadding="5">
<tbody>
<tr><td>Picture:</td><td><input name="rpic" type="file" accept="image/*"></td></tr>
<tr><td>Video:</td><td><input name="rvideo" type="file" accept="video/*"></td></tr>
<tr><td><input name="Upload Now" type="submit" value="Upload"></td></tr>
</tbody></table>
</form>

This is the script for inserting the files:
<?php
include("config.php");
error_reporting(E_ERROR | E_PARSE);

function GetImageExtension($rpic)
{
    if(empty($rpic)) return false;
    switch($rpic)
    {
        case 'image/bmp': return '.bmp';
        case 'image/gif': return '.gif';
        case 'image/jpeg': return '.jpg';
        case 'image/png': return '.png';
        default: return false;
    }
}
function GetVideoExtension($rvideo)
{
    if(empty($rvideo)) return false;
    switch($rvideo)
    {
        case 'video/asf': return '.asf';
        case 'video/avi': return '.avi';
        case 'video/wmv': return '.wmv';
        default: return false;
    }
}
if (!empty($_FILES["rpic"]["name"]))
{
    $file_name=$_FILES["rpic"]["name"];
    $temp_name=$_FILES["rpic"]["tmp_name"];
    $type=$_FILES["rpic"]["type"];
    $ext= GetImageExtension($type);
    $name=$_FILES["rpic"]["name"];
    $path = "uploads/".$name;

if(move_uploaded_file($temp_name, $path))
{
    $query_upload="INSERT into recipes (type, rpic, path, posted) VALUES ('".$type."','".$rpic."','".$path."','".date("Y-m-d")."')";
    mysql_query($query_upload) or die("Error in $query_upload == ----->".mysql_error());
} else {
    exit("Error while uploading your file.");
    }
}
if (!empty($_FILES["rvideo"]["name"]))
{
    $file_name=$_FILES["rvideo"]["name"];
    $temp_name=$_FILES["rvideo"]["tmp_name"];
    $type=$_FILES["rvideo"]["type"];
    $ext= GetVideoExtension($type2);
    $name=$_FILES["rvideo"]["name"];
    $path = "uploads/".$name;
    $pathvideo = "uploads/".$name;

if(move_uploaded_file($temp_name, $pathvideo))
{
    $query_upload="INSERT into recipes (type, rvideo, pathvideo, posted) VALUES ('".$type."','".$rvideo."','".$pathvideo."','".date("Y-m-d")."')";
    mysql_query($query_upload) or die("Error in $query_upload == ----->".mysql_error());
} else {
    exit("Error while uploading your file.");
    }
}
?>

Any help that anyone could provide would be appreciated.  Again, I would prefer to only have one record created.
Thanks in advance!

A:

Here you are inserting both the Photo & Video at same-time, In meantime you need to do both
 Validation & Db insertion. So,use the flag concept to attain this, 
// flag declaration
                        $flag_Photo=0;
                        $flag_Video=0;
                    if (!empty($_FILES["rpic"]["name"]))
                    {
                        $file_name=$_FILES["rpic"]["name"];
                        $temp_name=$_FILES["rpic"]["tmp_name"];
                        $type=$_FILES["rpic"]["type"];
                        $ext= GetImageExtension($type);
                        $name=$_FILES["rpic"]["name"];
                        $path = "uploads/".$name;

                    if(move_uploaded_file($temp_name, $path))
                    {
                      $flag_Photo=1;  
                    } 
                    else {
                        $flag_Photo=0;
                        //exit("Error while uploading your file.");
                        }
                    }
                    if (!empty($_FILES["rvideo"]["name"]))
                    {
                        $file_name=$_FILES["rvideo"]["name"];
                        $temp_name=$_FILES["rvideo"]["tmp_name"];
                        $type=$_FILES["rvideo"]["type"];
                        $ext= GetVideoExtension($type2);
                        $name=$_FILES["rvideo"]["name"];
                        $path = "uploads/".$name;
                        $pathvideo = "uploads/".$name;

                    if(move_uploaded_file($temp_name, $pathvideo))
                    {
                    $flag_Video=1; 

                    } else {
                        $flag_Video=0;
                        }
                    }
                    if($flag_Photo ==1 && $flag_Video==1)
                    {
                     $query_upload="INSERT into recipes (type, rpic, path, rvideo, pathvideo,  
                        posted) VALUES 

('".$type."','".$rpic."','".$path."','".$rvideo."','".$pathvideo."','".date("Y-m-d")."')";
                            mysql_query($query_upload) or die("Error in $query_upload == ----->".mysql_error());
                         }
                         else
                         {
                            exit("Error while uploading your file.");
                         }   

