Insert XML into MySQL table [closed]

0

I have an xml with the name of some movies, I want it when I press a button in html the names are inserted into a table in the database. I made the connection to php using ajax. The problem is that when I do the insertion, the first title is skipped and not inserted.

<script>
    $(document).ready(function() {

        $("#bInserir").click(function(){
            fInserir();
        });

        function fInserir()
        {
                $.ajax({
                type:"POST",
                dataType: "html",
                url: "revisao.php",
                success:function(ret){
                    alert(ret);
                    }
            });
        }
    });
</script>
<xml>
    <filme>
        <titulo>
            Assassinato no Expresso Oriente
        </titulo>
        <ano>
            2017
        </ano>
    </filme>
    <filme>
        <titulo>
            A Cabana
        </titulo>
        <ano>
            2016
        </ano>
    </filme>
</xml>
$xml_string = file_get_contents("revisao.xml");
$xml_object = simplexml_load_string($xml_string);

$conexao = mysqli_connect("localhost", "root", "root", "estudo");

foreach ($xml_object as $key) {


        mysqli_query($conexao, "INSERT INTO nota (titulo) VALUES ('$key->titulo')");
}

mysqli_close($conexao);
echo json_encode("Sucesso");
create table nota(
idnota int not null auto_increment,
titulo varchar(25) not_null,
primary key(idnota)
);

As an example, when this code I put is executed it is inserting only the title "The Hut" in the table and jumping the first one.

    
asked by anonymous 15.04.2018 / 19:43

1 answer

1

It is because the name of the movie exceeds the limit set in the creation of column (25)

titulo varchar(25) not_null,

"Murder on the East Express" has more than 25 characters.

    
15.04.2018 / 20:29