0
I have an xml with the name of some movies, I want when I press a button in html the names are inserted in 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 is 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 placed is executed it is only inserting the title "The Hut" in the table and skipping the first.
Damn my lack of attention, I always put 25. Thank you very much!
– Eduardo Ribeiro