Из-за чего возникает эта ошибка?
0
Ошибка:
Fatal error: Uncaught Error: Call to undefined function INSERT INTO movie VALUES(null, 'Джой', 'Joy', '2015', '', 'http://c.cineate.cc/media/m/4/5/154054/0.big.jpg', Now(), '1')() in C:\xampp\htdocs\kinomonster\index.php:50 Stack trace: #0 C:\xampp\htdocs\kinomonster\index.php(87): insert(Object(SimpleXMLElement), Object(SimpleXMLElement), Object(SimpleXMLElement), NULL, Object(SimpleXMLElement), 1) #1 {main} thrown in C:\xampp\htdocs\kinomonster\index.php on line 50
Мой код:
<?php
function insert($name, $desc, $year, $rating, $poster, $category_id) {
$mysqli = new mysqli('localhost', 'root', '', 'kinomonster');
if(mysqli_connect_errno()){
print_f('соединение не установлено');
exit();
}
$mysqli->set_charset('utf8');
$query = "INSERT INTO movie VALUES(null, '$name', '$desc', '$year', '$rating', '$poster', Now(), '$category_id')";
$result = false;
if($mysqli-$query($query)){
$result = true;
}
return $result;
}
$xml = simplexml_load_file("xml_files/movies.xml") or die("Error:Cannot create object");
//echo count($xml);
$title = null;
$title_origin = null;
$post = null;
$rating = null;
$year = null;
foreach ($xml as $movie_key => $movie) {
$title = $movie->title_russian;
$title_origin = $movie->title_original;
$year = $movie->year;
foreach ($movie->poster->big->attributes() as $poster_key => $poster) {
$post = $poster;
}
if($movie->imdb){
$rating = $movie->imdb->attributes()['rating'];
}
insert($title, $title_origin, $year, $rating, $post, 1);
}
echo "<pre>";
print_r($xml);
echo "</pre>";
?>
1 ответов
1
Подключение к базе данных точно есть?
Тут есть разбор примера insert с xml от преподавателя:
https://fructcode.com/ru/qa/ne-dobavlaetsa-zapis-iz-xml-v-bd-cto-delau-nepravilno-jlsfdn/