Jump to content

Such a Simple error to fix - but I cant - please help


Recommended Posts

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???

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.

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.

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

<?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.

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"; 	?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.