Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

insert list of array into mysql database with php

i have a list of array that needs to be insert to database, can you help me how? its a list of exif data from image folder named uploads, every array consist selected exif to be stored

this is the array

Array
(
    [0] => Array
        (
            [FileName] => foto1.jpg
            [Model] => SM-A528B
            [Longitude] => 106.79185497222
            [Latitude] => -6.168561
        )

    [1] => Array
        (
            [FileName] => foto2.jpg
            [Model] => SM-A528B
            [Longitude] => 106.79185497222
            [Latitude] => -6.168561
        )

)

this is the code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

   $dir = 'uploads/';
    $files = scandir($dir);

    $ext_list = ['jpg','gif','png','heic','JPG','PNG','JPEG','GIF'];   

    foreach($files as $image_file)
    {
        $l = strtolower($image_file);
        $parse_file_name = explode(".",$l);
        $file_ext = end($parse_file_name);

        if(in_array($file_ext,$ext_list))
        {


            $exif_data = exif_read_data($dir.$image_file);
           
            $lon = getGps($exif_data["GPSLongitude"], $exif_data['GPSLongitudeRef']);
            $lat = getGps($exif_data["GPSLatitude"], $exif_data['GPSLatitudeRef']);
            $photos[] = [
              'FileName'=>$exif_data['FileName'],
              'Model'=>$exif_data['Model'],
              'Longitude'=>$lon,
              'Latitude'=>$lat,
            ];
            
     $insert = $db->query("INSERT INTO exif_foto (file_name, Model,Longitude,Latitude) VALUES ( , '$p_image')"); //I want to correct this, this is still wrong.

           
        }
        
    }
    // $insertexif =  INSERT INTO Destinasi('');
            // mysqli_query($con,$insertexif);
            print"<pre>";
            print_r($photos);
            print"<pre>";

Any suggestions how to do it?

>Solution :

Your Insert can be devided as follows :

$sql = sprintf("INSERT INTO exif_foto (file_name, Model, Longitude, Latitude) VALUES ('%s', '%s', '%s', '%s')", $exif_data['FileName'], $exif_data['Model'], $lon, $lat);
$insert = $db->query($sql);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading