ikon Posted April 27, 2008 Share Posted April 27, 2008 Hi all, How can i hide a "Notice:" error? The reason i need it is because i'm trying to show a session variable thats not there untill the next part of my code however the "notice" i'm getting is Notice: Undefined index:....... Anyone know how to hide this??? Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/ Share on other sites More sharing options...
AndyB Posted April 27, 2008 Share Posted April 27, 2008 change the error_reporting() level ... a notice is a notice, i.e. warning. It's not an error. Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/#findComment-528301 Share on other sites More sharing options...
ikon Posted April 27, 2008 Author Share Posted April 27, 2008 where's the error reporting level?? Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/#findComment-528302 Share on other sites More sharing options...
DarkWater Posted April 27, 2008 Share Posted April 27, 2008 error_reporting(E_ALL & ~E_NOTICE); Although that's the default level (no notices), yours displays notices, lol. Put that line on the page. Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/#findComment-528326 Share on other sites More sharing options...
ikon Posted April 27, 2008 Author Share Posted April 27, 2008 Hi that didn't seem to work, perhaps i've put it in the wrong place..... let me just explain what i'm trying to do. Before a user uploads a photo they get to the same screen that they would after they've uploaded their photo. This page includes the session variable "photo" which once they've uploaded their photo says "your have uploaded photo name...... bla bla bla" However, because the same screen tries to echo the session varaible before that session is created.... it displays the notice: "Notice: Undefined index: photo" What i was going to try and do was this <?php if(session_exists["photo"]) { die("No Current Photo Uploaded"); } else { echo "The file.... ". basename( $_SESSION['photo']). " has been added"; } ?> Which would show "no current photo uploaded" if the photo session wasn't there but if it was then show the file x.jpg has been added All i am currently doing is this: <?php echo "The file.... ". basename( $_SESSION['photo']). " has been added for this product";?> </p> <p><strong><?php echo $pd_name; ?></strong><br> Price : <?php echo ($pd_price); ?><br> I would love for example 1 to work but if we could just hide the error that would also be sufficiant. Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/#findComment-528337 Share on other sites More sharing options...
DarkerAngel Posted April 27, 2008 Share Posted April 27, 2008 Hi that didn't seem to work, perhaps i've put it in the wrong place..... let me just explain what i'm trying to do. Before a user uploads a photo they get to the same screen that they would after they've uploaded their photo. This page includes the session variable "photo" which once they've uploaded their photo says "your have uploaded photo name...... bla bla bla" However, because the same screen tries to echo the session varaible before that session is created.... it displays the notice: "Notice: Undefined index: photo" What i was going to try and do was this <?php if(session_exists["photo"]) { die("No Current Photo Uploaded"); } else { echo "The file.... ". basename( $_SESSION['photo']). " has been added"; } ?> Which would show "no current photo uploaded" if the photo session wasn't there but if it was then show the file x.jpg has been added All i am currently doing is this: <?php echo "The file.... ". basename( $_SESSION['photo']). " has been added for this product";?> </p> <p><strong><?php echo $pd_name; ?></strong><br> Price : <?php echo ($pd_price); ?><br> I would love for example 1 to work but if we could just hide the error that would also be sufficiant. Adding a '@' before a line of code will suppress an error message, either that or use the error_reporting(E_ALL & ~E_NOTICE); as stated. Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/#findComment-528339 Share on other sites More sharing options...
ikon Posted April 27, 2008 Author Share Posted April 27, 2008 thanks for your response but i dont quite know where i'd put the @.... do you mean like this? @<?php echo "The file.... ". basename( $_SESSION['photo']). " has been added for this product"; ?> or <?php @ echo "The file.... ". basename( $_SESSION['photo']). " has been added for this product"; ?> or <?php error_reporting(E_ALL & ~E_NOTICE); ?> <?php echo "The file.... ". basename( $_SESSION['photo']). " has been added for this product"; ?> Thanks for your current responses Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/#findComment-528346 Share on other sites More sharing options...
Fadion Posted April 27, 2008 Share Posted April 27, 2008 <?php if(!isset($_SESSION['photo'])){ die("No Current Photo Uploaded"); }else{ echo "The file.... ". basename($_SESSION['photo']) . " has been added"; } ?> I guess session_exists() was to illustrate what u needed, or a custom function as there's no such thing in php. Use isset() instead. Also dont use die() when u want to print an error message, it will stop all the code and html u have below that line. Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/#findComment-528352 Share on other sites More sharing options...
ikon Posted April 27, 2008 Author Share Posted April 27, 2008 ok i think i'm just going to hide the error..... can someone give me a hand on where the <?php error_reporting(E_ALL & ~E_NOTICE); ?> needs to go please? Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/#findComment-528357 Share on other sites More sharing options...
DarkerAngel Posted April 27, 2008 Share Posted April 27, 2008 ok i think i'm just going to hide the error..... can someone give me a hand on where the <?php error_reporting(E_ALL & ~E_NOTICE); ?> needs to go please? it would go at the beginning of the PHP file Also if I'm not mistaken it should have been: <?php echo "The file.... ". @basename( $_SESSION['photo']). " has been added for this product"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/#findComment-528361 Share on other sites More sharing options...
ikon Posted April 27, 2008 Author Share Posted April 27, 2008 Thanks a lot All, the notice is now hidden Many thanks to everyone who took time to read this and help me out. Darker Angel - you legend! ha ha Quote Link to comment https://forums.phpfreaks.com/topic/103140-such-a-simple-error-to-fix-but-i-cant-please-help/#findComment-528371 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.