Как сделать домашнее задание 60?

0

В чём ошибка?

<?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/movies.xml") or die("Error: Cannot create object");

//echo count($xml);

$title = null;
$decr= null;
$post = null;
$rating = null;
$year = null;

foreach ($xml as $movie_key => $movie) {
$title = $movie->title_russian;
$year = $movie->year;


foreach ($movie->poster->big->attributes() as $poster_key => $poster) {
$post = $poster;
}
foreach ($movie->poster->desk as $desk_key => $desc) {
$decr = $desc;
}

if($movie->imdb) {
$rating = $movie->imdb->attributes()['rating'];
} else {
$rating = null;
}

insert($title, $decr, $year, $rating, $post, 1);

}

echo "<pre>";
print_r($xml);
echo "</pre>";

?>
php
mysql

1 ответов

1

Проблему решил за 3 часа, Обращайте внимание на таблицу!

Sign up or Log in to write an answer