I am connecting to a local database and want to store the values of a json into it, the current code i have is:
<?php
$servername = 'localhost';
$username = 'username';
$password = 'pass';
$databaseName = 'databasename';
$con = new mysqli($servername,$username,$password,$databaseName);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
echo "Connected successfully\n";
$jsondata = file_get_contents('prices.json');
$data = json_decode($jsondata, true);
foreach ($data as $name) {
$price = ($name['buff163']['starting_at']['price'] * 0.141279);
$sql = "INSERT INTO prices(name, price) VALUES('$name', '$price')";
}
?>
Although with any changes i have tried to make i get the same error
PHP Warning: Invalid argument supplied for foreach() in /var/scripts/priceupdate.php on line 14
What am i doing wrong? it seems to be working for other people.