inserting 4 different files into 1 SQL table row in php

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



inserting 4 different files into 1 SQL table row in php



As the title says, i want to parse 4 different files and insert them into 1 sql row. I have parsed the files so i have the information, however its not inserting into my table.
This is the code I have. I eliminated the actual sql names and values to save time. My two main questions are 1) is this the right way to do this and 2) is there a better way.


<?php

$connect = mysqli_connect("reserve1", "root", "","server_31");
$dir = "/Users/Administrator/Desktop/Reserve1";
if (is_dir($dir))
if ($dh = opendir($dir))

foreach(glob("*.json") as $filename)
$data = file_get_contents($filename);
$array = json_decode($data, true);
foreach($array[0]as $row)
$sql = "INSERT INTO servers_updated (---)
VALUES ('---)";
$connect->query($sql);



foreach(glob("*_processor.json") as $filename)
$data = file_get_contents($filename);
$info = json_decode($data, true);
foreach($info[1] as $row)
$sql = "INSERT INTO servers_updated
(--- ) VALUES (---)";
$connect->query($sql);


foreach(glob("*_drives.json") as $filename)
$data = file_get_contents($filename);
$info = json_decode($data, true);
foreach($info[1] as $row)
$sql=" INSERT INTO servers_updated (---) VALUES (---)";
$connect->query($sql);


foreach(glob("*_memory.json") as $filename)
$data = file_get_contents($filename);
$stuff = json_decode($data, true);
foreach($stuff[1] as $row)
$sql =" INSERT INTO servers_updated
(--- ) VALUES (----)";
$connect->query($sql);







?>





Is it me or it lacks one }?
– Mickael Leger
Aug 10 at 15:33


}





It might, it would be from copying and pasting but you were right i was missing 1 at the end and added it.
– John Monte
Aug 10 at 15:38






Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help you debug your code Take a quick look at a coding standard for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end.
– RiggsFolly
Aug 10 at 17:19





I will take a read, thanks!
– John Monte
Aug 10 at 17:39









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS