Problems when inserting data from a json file to mysql DB

0

My problem is that I try to enter the data from a JSON file to my bd mysql but only certain records are added and there my doubt.

Why are not all the records added? and I do not know how to find the error.

I've done it before with many JSON files and I had not encountered this problem. The following is my PHP code.

    <?php

  require('db.php');
  include 'obtenerImagen.php';
  $json = file_get_contents("../json/archivo.json");

  $conexion = mysqli_connect($host, $user, $pass, $databaseName) 
  or die("Ha sucedido un error inesperado en la conexion de la base de datos");

  $noticiasData = json_decode($json, true);

  foreach ($noticiasData as $noticias) {

    $titulo = $noticias['title']['__cdata'];
    $link = $noticias['link'];
    $img = obtenerImg($noticias['description']['__cdata']); 
    $fecha = str_replace("T"," ",$noticias['date']['__text']);
    $fecha = substr($fecha, 0,19);
    $descripcion = $noticias['description']['__cdata'];

    mysqli_query($conexion,"INSERT INTO fullNews (titulo,link,img,fecha, descripcion) VALUES ('$titulo', '$link', '$img', '$fecha', '$descripcion')");

  } 

  mysqli_close($conexion);

 ?>

If I print the results, it shows me all the records correctly but in the database only one is added.

Here is the JSON file:

[

     {
        "title": {
           "__cdata": "Famosos 'gamer': la cantante Lady Gaga, fan de 'Bayonetta', se suma al club de los aficionados por los videojuegos"
        },
        "link": "https://www.20minutos.es/videojuegos/noticia/famosos-gamer-cantante-lady-gaga-club-aficionados-videojuegos-3482700/0/",
        "description": {
           "__cdata": "<p>INÉS LÓPEZ</p> <ul><li>La artista escribió un tuit en el que contaba que se había pasado el cuarto capítulo de 'Bayonetta'.</li><li>Otros famosos que son reconocidos 'gamers' son Megan Fox, Matthew Perry y Daniel Craig.</li></ul><p><img src=\"https://cdn.20m.es/img2/recortes/2018/11/05/817731-620-282.jpg?v=20181105130414\" width=\"620\" height=\"282\" alt=\"Lady Gaga y Bayonetta\" /></p><p>La cantante más extravagante de Estados Unidos,<a href=\"https://www.20minutos.es/minuteca/lady-gaga/\"><strong> Lady Gaga </strong></a>ha desvelado a través de su cuenta de Twitter su <strong>afición por los <a href=\"https://www.20minutos.es/videojuegos/minuteca/videojuegos/\">videojuegos</a></strong>. En concreto, ha comentado que está disfrutando del título <em>Bayonetta,</em> recientemente lanzado en <a href=\"https://www.20minutos.es/videojuegos/minuteca/nintendo-switch/\">Nintendo Switch</a>.</p><p>En su tuit ha celebrado que <strong>ha conseguido terminar el cuarto capítulo del juego</strong> sin especificar en qué plataforma lo está jugando (<em>Bayonetta</em> debutó en 2010 en PlayStation 3 y Xbox 360, apareció en Wii U en 2014 y hace poco ha llegado a Nintendo Switch).</p><p>Independientemente,<strong> la compañía <a href=\"https://www.20minutos.es/videojuegos/minuteca/nintendo/\">Nintendo</a> ha respondido a la artista</strong> a través de su cuenta americana para darle ánimos para que supere con éxito el quinto capítulo del videojuego.</p><div><blockquote class=\"twitter-tweet\" data-lang=\"es\"><p dir=\"ltr\">You got this!                     
asked by Richard Hearn 14.11.2018 в 19:20
source

0 answers