input_image.php

<?php

$result = mysql_query("SELECT * FROM image_upload ORDER BY image_id ASC");

$data = mysql_fetch_array($result);

$banner = $data['image_bn'];

?>

<p><img src="../../images/<?php $banner; ?>"></p>

<?php echo $_SESSION[$banner]; ?>

line 13: Notice: Undefined index: adm_banner.jpg in C:\xampp\htdocs\portal\administrator2\admin\input_image.php on line 76

How to fix the error?

Recommended Answers

All 14 Replies

Is line 76 of the input_image.php actually a line 13 in the above snippet? If yes, obviously $_SESSION['adm_banner.jpg'] does not exist. Where is it supposed to be set?

yes, line 13 = line 76.

It is set in here:

input_image.php

$banner = $data['image_bn'];

Yes, but where is the $_SESSION['adm_banner.jpg'] being set? If you want to echo it you have to set it first.

I agree with Broj1 .

<?php echo $_SESSION[$banner]; ?>

$banner = $data['image_bn'];

$banner = 'adm_banner.jpg'; // it gets from $data['image
_bn'];

OK, again. Where is the $_SESSION['adm_banner.jpg'] getting set?

On line 7 in your first post you assign a value from the database to the $banner variable:

$banner = $data['image_bn'];

Then on line 13 you try to echo the $_SESSION[$banner] variable:

echo $_SESSION[$banner];

From the error message it seems that the value of the $banner variable is adm_banner.jpg. So you are essentially trying to echo the $_SESSION['adm_banner.jpg'] variable. The question is: has the $_SESSION['adm_banner.jpg'] been set at all anywhere in the code? It seem not. I guess you have an error in your logic.

I already place this code on top of:

input_image.php

<?php

session_start();

?>

Still does not answer my question: has the $_SESSION['adm_banner.jpg'] been set at all anywhere in the code? Is there a line saying:

$_SESSION['adm_banner.jpg'] = 'something';

or maybe:

$_SESSION[$banner] = 'something';

so you can then echo it. I doubt it is. You probably have an error in your logic. Try to describe what you want to achieve.

I only except when you print

<?php echo $_SESSION[$banner]; ?>

It prints something like: adm_banner.jpg

instead of: Notice: Undefined index: adm_banner.jpg in C:\xampp\htdocs\portal\administrator2\admin\input_image.php on line 76

Maybe it should be:

<?php echo $_SESSION['banner']; ?>

but I can't tell without seeing the code where you set the $_SESSION value.

Well, this is the whole session code part:

<?php

    include('includes/koneksi.php');    

    session_start();
?>

<?php

$result = mysql_query("SELECT * FROM image_upload ORDER BY image_id ASC");

$data = mysql_fetch_array($result);

$banner = $data['image_bn'];

?>

<p><img src="../../images/<?php $banner; ?>"></p>

<?php echo $_SESSION[$banner]; ?>

I still do not understand what's wrong.

You can not echo $_SESSION[$banner] if $_SESSION[$banner] has not been set before.

I already try redefining the value:

$_SESSION[$banner] = $data['image_bn'];

<?php echo $_SESSION[$banner]; ?>

------------------------

Notice: Undefined variable: banner in C:\xampp\htdocs\portal\administrator2\admin\input_image.php on line 72

line 79:Notice: Undefined variable: banner in C:\xampp\htdocs\portal\administrator2\admin\input_image.php on line 79
adm_banner.jpg

YOu are giving code i pieaces please post here whole code at once.Along with index file.
ANd also please check this one .
<p><img src="../../images/<?php $banner; ?>"></p>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.