How to insert multiple images path to database

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • ghjk
    replied
    I have done it. This is the code..
    Code:
    if (isset($_POST['Submit'])) {
    	echo $_SESSION['vehicles_pk'];
        $number_of_file_fields = 0;
        $number_of_uploaded_files = 0;
        $number_of_moved_files = 0;
        $uploaded_files = array();
        $upload_directory = dirname(__file__) . '/vehicles/'; //set upload directory
        // * we get a $_FILES['images'] array ,
        // * we procee this array while iterating with simple for loop 
        // * you can check this array by print_r($_FILES['images']); 
         
        for ($i = 0; $i < count($_FILES['images']['name']); $i++) {
            //$number_of_file_fields++;
            if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not
                $number_of_uploaded_files++;
                $uploaded_files[] = $_FILES['images']['name'][$i];
                if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) {
                   $number_of_moved_files++;
    				//echo $number_of_moved_files++;
    				$sql ="INSERT INTO images  VALUES ('', '".$_SESSION['vehicles_pk']."','".$upload_directory . $_FILES['images']['name'][$i]."')";
    				
    				$result = mysql_query($sql);
    	
                }
    
            }
    		unset($_SESSION['vehicles_pk']);
     
        }
    
    }

    Leave a comment:


  • ghjk
    replied
    Actually I want the help of insert query. I don't know how to do that for multiple values.(one field has multiple values)

    Leave a comment:


  • johny10151981
    replied
    HOw about this structture?
    AutoId-----UserId-----UserPicture
    1-----User1-----UserPicture1
    2-----User2-----UserPicture2
    3-----User3-----UserPicture3

    Leave a comment:


  • ghjk
    started a topic How to insert multiple images path to database

    How to insert multiple images path to database

    In my application I want to store vehicle details to mysql database. There is image field which is having more than 1 images.(select from the user) It may be 3 ,4 ,5 etc.image table has image id and image path field.When submit button click I want to add images to vehicle folder(this part working) and all images paths to the database. Really I'm wired now. I don't know how to add multiple images record to the database. Please help me. This is my existing code.

    Code:
    if (isset($_POST['Submit'])) {
    
    	$vehicles_pk = mysql_insert_id(); // get last inserted vehicle id
        $number_of_file_fields = 0;
        $number_of_uploaded_files = 0;
        $number_of_moved_files = 0;
        $uploaded_files = array();
        $upload_directory = dirname(__file__) . '/vehicles/'; //set upload directory
       
        // * we get a $_FILES['images'] array ,
        // * we procee this array while iterating with simple for loop 
        // * you can check this array by print_r($_FILES['images']); 
         
        for ($i = 0; $i < count($_FILES['images']['name']); $i++) {
            $number_of_file_fields++;
            if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not
                $number_of_uploaded_files++;
                $uploaded_files[] = $_FILES['images']['name'][$i];
                if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) {
                    $number_of_moved_files++;
    			
                }
    
            }
     
        }
    $name= implode(',', $uploaded_files);
    echo $name; // this will print 1.jpg,2.jpg
Working...