As a simple answer maybe there is '
single-quote in your json values.
Old solution:
Security Warning: Escaping is inadequate to prevent SQL injection, use prepared
statements instead. Use the strategy outlined below at your own risk.
(Also, mysql_real_escape_string() was removed in PHP 7.)
You can using mysqli::real_escape_string
to fix it.
<?Php
$connect = mysqli_connect("localhost","test","test","beers");
$url = file_get_contents("https://api.punkapi.com/v2/beers");
$json = json_decode($url, true);
foreach ($json as $row) {
$sql = "INSERT INTO Brewdog (naam, tagline, omschrijving) VALUES ('".mysqli_real_escape_string($connect, $row['name'])."','".mysqli_real_escape_string($connect, $row['tagline'])."',,'".mysqli_real_escape_string($connect, $row['description'])."')";
mysqli_query($connect, $sql);
}
echo "klaar is kees";
?>
https://www.php.net/manual/en/mysqli.real-escape-string.php
UPDATE security issue
use mysqli prepare in order avoiding sql injection
$stmt = $connectn->prepare('INSERT INTO Brewdog (naam, tagline, omschrijving) VALUES (?, ?, ?');
$stmt->bind_param('sss', $row['name'],$row['tagline'],$row['tagline']); // 's' specifies the variable type => 'string'
$stmt->execute();