Не добавляется запись из xml в бд. что делаю неправильно?

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')";

		$xml = simplexml_load_file("xml/movies.xml") or die("Error: Cannot creat object");

		$result = false;
		if ($mysqli->query($query)) {
			$result = true;
		}

		return $result;
	}
	$xml = simplexml_load_file("xml/movies.xml") or die("Error: Cannot creat obj```ect");

	# echo count($xml);

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


	foreach($xml as $movie_key => $movie) {
		$title =  $movie->title_russian;
		$title_orign = $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_orign, $year, $rating, $post, 1);
	}

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

	
 ?>

что делаю неправильно?

mysql

1 ответов

0

Попробуйте без null и явно указать поля для запроса:

$query = "INSERT INTO movies (name, desc, year, rating, poster, add_date, category_id)
VALUES('$name','$desc','$year','$rating','$poster',Now(),'$category_id')";
Sign up or Log in to write an answer