cat250 Posted January 12, 2012 Share Posted January 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254870-not-found-error/ Share on other sites More sharing options...
thewebsolutionprovider Posted January 12, 2012 Share Posted January 12, 2012 You can use an IF: if ( isset ( $json['Poster'] ) ) { // do what you need here } else { // set error here } Quote Link to comment https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1306829 Share on other sites More sharing options...
kicken Posted January 12, 2012 Share Posted January 12, 2012 if (!isset($json['Poster'])){ //not found } else { //found } Quote Link to comment https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1306845 Share on other sites More sharing options...
cat250 Posted January 12, 2012 Author Share Posted January 12, 2012 if (!isset($json['Poster'])){ //not found } else { //found } Thanks, but isn't working. Tried with this: if (!isset($json['Poster'])){ echo "Hi."; } else { echo "Bye."; } Get "Bye." Quote Link to comment https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1306858 Share on other sites More sharing options...
wolfcry Posted January 12, 2012 Share Posted January 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1306864 Share on other sites More sharing options...
cat250 Posted January 12, 2012 Author Share Posted January 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1306995 Share on other sites More sharing options...
jcbones Posted January 12, 2012 Share Posted January 12, 2012 You will have to post more code. The answers you have been given are correct. If for some reason they are not working for you, then there must be something else in the code causing it to break. Quote Link to comment https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1307067 Share on other sites More sharing options...
cat250 Posted January 12, 2012 Author Share Posted January 12, 2012 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']."' />"; Quote Link to comment https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1307084 Share on other sites More sharing options...
jcbones Posted January 13, 2012 Share Posted January 13, 2012 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']."' />"; } Quote Link to comment https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1307096 Share on other sites More sharing options...
cat250 Posted January 13, 2012 Author Share Posted January 13, 2012 Many thanks. Finally solved. Quote Link to comment https://forums.phpfreaks.com/topic/254870-not-found-error/#findComment-1307099 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.