Jump to content

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


ikon

Recommended Posts

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

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.