插入不正常工作

I have a code that help me to upload 6 files to the server and also add the information to the DataBase, the code works great when upload the files BUT when it will safe the information to the database just save the first one. Can you please help me,

This is the code

$i=0;
    while ($i<=10){
        if (isset($_FILES['ufile']['name'][$i]) and ($_FILES['ufile']['name'][$i]<>"")){
            $path[$i] = "../slider_new/".$_FILES['ufile']['name'][$i];  
            $path[$i] =  str_replace(' ', '_',$path[$i]);
            copy($_FILES['ufile']['tmp_name'][$i], $path[$i]);
            echo "Ruta :".$path[$i]."<BR/>";
            echo "File Name :".$_FILES['ufile']['name'][$i]."<BR/>"; 
            echo "File Size :".$_FILES['ufile']['size'][$i]."<BR/>"; 
            echo "File Type :".$_FILES['ufile']['type'][$i]."<BR/>"; 
            echo "<img src=\"$path[$i]\" width=\"150\" height=\"150\">";
            echo "<P>";
            $sql="INSERT INTO accommo_main_images (num,name,ruta) values('".$num."','".$_FILES['ufile']['name'][$i]."','".$path[$i]."')";
            $res=mysqli_query($cnx,$sql);        
        }
        $i=$i+1;

    }

Change single quote from query in num field is

$sql = "INSERT INTO accommo_main_images (num,name,ruta) values(".$num.",'".$_FILES['ufile']['name'][$i]."','".$path[$i]."')";min 

You can print query like echo $sql; and check it in phpmyadmin or other tool will help remove error from query

I found the problem, the code work 100%, the problem was that I setup the nun like the Primary so for this reason just the first item was save, I added the "id" and setup like a Primary and all the images was seve to the data base

Thank you everyone and sorry