How to use this variable?

Hey guys. I’m using the IMDB api to extract IMDB information but im unsure how to pass the info to my DB.

This code works great
[php]$imdb_json=file_get_contents(“http://imdbapi.org/?title=title”);
$imdb_info=json_decode($imdb_json);
echo “”;
echo “”;
echo “”;
echo “”;
echo " " .$imdb_info[0]->title;
echo " ";
echo " " .$imdb_info[0]->runtime[0];
echo " ";
echo " " .$imdb_info[0]->rating;
echo “”;
echo " plot simple " . $imdb_info[0]->plot_simple;
echo “”;[/php]

but when I try to pass it into the database using

[php]$sql=“INSERT INTO database ( title)
VALUES
(’$imdb_info[0]->plot_simple’)”;[/php]

it breaks the code. Looks like its some type of syntax error. Hoping you could point me at the right direction.

Because I don’t know the exact error you are getting and for the most part the code looks functional, I can only point out one thing that looks off to me, but I can’t be positive if it’s going to solve your problem or if it’s just a typo, but:

[php]$sql=“INSERT INTO database ( title)
VALUES
(’$imdb_info[0]->plot_simple’)”;[/php]

You say “database”, but this should be the “tablename”

[php]$sql=“INSERT INTO tablename ( title)
VALUES
(’$imdb_info[0]->plot_simple’)”;[/php]

Like I said, not sure if this was just a typo, but from the little info its really the only thing I see out of place.

Also, you can’t use that complex of a var in quotes. You need to do one of the following:

[php]$sql = “INSERT INTO database (title)
VALUES
(’{$imdb_info[0]->plot_simple}’)”;

//or

$sql = “INSERT INTO database (title)
VALUES
(’” . $imdb_info[0]->plot_simple . “’)”;[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service