62 урок, задание

0

Выдает такую ошибку :

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''name','descriptions','year','rating','poster', 'add_date','category_id') VALUES' at line 1

В чем может быть проблeма?

php
mysql

2 ответов

1

Покажите весь ваш код.

Судя по ошибке у вас с кавычками что-то не так - идут одинаковые две кавычки:

''name','descriptions','year','rating','poster', 'add_date','category_id')
1

<?php

function insert($name, $desc, $year, $rating, $poster, $category_id) {
$mysqli = new mysqli("localhost", "root", "", "kinomonster");


if (mysqli_connect_errno()) {
print_f("Соединение не установлено", mysql_connect_error());
exit();
}

$mysqli->set_charset('utf8');

$query = "INSERT INTO movie ('name','descriptions','year','rating','poster', 'add_date','category_id') VALUES ('$name',
'$desc', '$year', '$rating', '$poster', Now(),'$category_id')";
$result = false;
if($mysqli -> query($query) or die( $mysqli->error ) ) {
$result = true;
}
return $result;

}


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

//echo count($xml);

$title = null;
$title_orign = null;
$post = null;
$rating = null;
$desc = 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"];
} else {
$rating = null;

}

insert($title, $title_orign, $year, $rating, $post, 2);

}

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

?>

Sign up or Log in to write an answer