Jump to content

Not found error


cat250

Recommended Posts

One more problem...  I'm sorry if I bother u.

 

I have:

echo "Image: ".$json['Poster'].""; and if image exist I get in return URL... but if there's no image get a error:

Notice: Undefined index: Poster in C:\xampp\htdocs\file.php on line 48

 

How can I show a message error for this?

 

Maybe I have too many questions but it's first time when I use PHP and don't understand too much.

Help is appreciated, again. Thanks!

 

I readed about if, else... still can't solved.

Link to comment
https://forums.phpfreaks.com/topic/254870-not-found-error/
Share on other sites

It's working as it should, you just have your messages flipped.

 

Change echo "Hi" with echo "Bye" and vice versa.

 

The 'else' part is what's supposed to happen IF json['Poster'] IS set.

 

To get a better understanding of this, instead of using "Hi and Bye" as your test messages, try this:

 

if (!isset($json['Poster'])){
   echo "Poster is NOT set!";
}
else {
  echo "Poster IS set!";
}

 

Hope that helps :)

Link to comment
https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1306864
Share on other sites

It's working as it should, you just have your messages flipped.

 

Change echo "Hi" with echo "Bye" and vice versa.

 

The 'else' part is what's supposed to happen IF json['Poster'] IS set.

 

To get a better understanding of this, instead of using "Hi and Bye" as your test messages, try this:

 

if (!isset($json['Poster'])){
   echo "Poster is NOT set!";
}
else {
  echo "Poster IS set!";
}

 

Hope that helps :)

 

Ok, now i get "Poster IS set!"... but that isn't true. This is what i wanted to say above.

 

I try to explain again: I have in mysql 2 entries, one with poster and one without.

Script return "Poster IS set!" in both cases. :)

Link to comment
https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1306995
Share on other sites

mysql_connect("localhost", "root", "") or die(mysql_error());

mysql_select_db("movies") or die(mysql_error());

$f = mysql_query("SELECT * FROM movies") or die(mysql_error());

while($inf = mysql_fetch_assoc($f)) {

$two= $inf['id'];

$link = "http://www.imdbapi.com/?i=$two";

$thr = file_get_contents($link);

$json = json_decode($thr,true);

echo "<img src='".$json['Poster']."' />"; 

Link to comment
https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1307084
Share on other sites

Perhaps Poster is set, but is empty.

 

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("movies") or die(mysql_error());
$f = mysql_query("SELECT * FROM movies") or die(mysql_error());
while($inf = mysql_fetch_assoc($f)) {
$two= $inf['id'];
$link = "http://www.imdbapi.com/?i=$two";
$thr = file_get_contents($link);
$json = json_decode($thr,true);
if(!empty($json['Poster'])) { echo "<img src='".$json['Poster']."' />";  }

Link to comment
https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1307096
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.