I have some errors while trying to fix the following codes:

update_image2.php

<?php
                //LOAD IMAGE TABLE

                if (!empty($_GET['image_id'])){
                $result = mysql_query("SELECT * FROM image_upload WHERE image_id='".$_GET['image_id']."'") or die(mysql_error());

                $data = mysql_fetch_array($result);

                $image_id = $_GET['image_id'];
                $newfilename = $data['newfilename'];
                $class = $data['class'];
                $location = $data['location'];
                $minwidth = $data['minwidth'];
                $maxwidth = $data['maxwidth'];
                $minheight = $data['minheight'];
                $maxheight = $data['maxheight'];
                }
                else {
                    //echo "unable to select data".'<br>';
                    //echo "package_id is empty";
                    $image_id = "";
                    $newfilename = "";
                    $class = "";
                    $location = "";
                    $minwidth = "450";
                    $maxwidth = "550";
                    $minheight = "600";
                    $maxheight = "700";

                }
                ?>

                <form method="post" action="<?php echo $_SERVER['PHP_SELF'] .'?image_id='. $image_id;?>" enctype="multipart/form-data">

                            <b>Class name :</b>  <input type="text" name="class" value="<?php echo $class; ?>"><br><br><br>

                            <?php                            

                            echo '<div id="location"><b>Location: <input type="text" size="50px" name="location" value="'.$location.'" disabled></b></div><br><br><br>';

                            echo '<input type="text" size="30px" name="location" value="'.$location.'" hidden>';

                            echo '<div id="size"><b>min width: <input type="text" size="10px" name="size" value="'.$minwidth.'px" disabled></b></div><br><br><br>';

                            echo '<div id="size"><b>max width: <input type="text" size="10px" name="size" value="'.$maxwidth.'px" disabled></b></div><br><br><br>';

                            echo '<div id="size"><b>min height: <input type="text" size="10px" name="size" value="'.$minheight.'px" disabled></b></div><br><br><br>';

                            echo '<div id="size"><b>max height: <input type="text" size="10px" name="size" value="'.$maxheight.'px" disabled></b></div><br><br><br>';
                            echo $data['image'];

                            echo '<div id="updateimage"><img src="images/'.$data['newfilename'].'" height="250px"></updateimage>';

                            echo '<br><br><br>.<input type="file" value="upload" name="file"/><br><br>';

                            ?>

Notice: Undefined variable: data in C:\xampp\htdocs\portal\administrator2\admin\update_image2.php on line 407

Notice: Undefined variable: data in C:\xampp\htdocs\portal\administrator2\admin\update_image2.php on line 409

echo $data['image'];

echo '<div id="updateimage"><img src="images/'.$data['newfilename'].'" height="250px"></updateimage>';

Recommended Answers

If you do not have image ID then $data array is not set. You should check for it before using it, especially in these two lines:

if(isset($data['image']) && isset( $data['newfilename'])) {
    echo $data['image'];
    echo '<div id="updateimage"><img src="images/'.$data['newfilename'].'"  height="250px"></div>';
}
Jump to Post

I'm going to come right out with it.
You've been here since 2011; asking and asking. Not solving a single thing yourself. One challenge in programming is problem solving. And when things are just given to you... you learn nothing. Let's analyse "Undefined variable". "Undefined" means that it hasn't been …

Jump to Post

All 5 Replies

you could hide all these notices by modifying the error reporting parameter as below, just for the current executing script, or directly on the server php.ini file error_reporting(E_ALL ^ E_NOTICE);

I think you are using global variables directly .And in last line i dont understand where from you are getting this echo '<div id="updateimage"><img src="images/'.$data['newfilename'].'" height="250px"></updateimage>';

</updateimage> it should be </div> there

If you do not have image ID then $data array is not set. You should check for it before using it, especially in these two lines:

if(isset($data['image']) && isset( $data['newfilename'])) {
    echo $data['image'];
    echo '<div id="updateimage"><img src="images/'.$data['newfilename'].'"  height="250px"></div>';
}

Agree with broj1.

You initiated the $data variable if image id is passed to the page (Line 7), but you did NOT initiate the same variable if there is no image id. Then, all of the sudden, you attempt to use the variable on the page...

I'm going to come right out with it.
You've been here since 2011; asking and asking. Not solving a single thing yourself. One challenge in programming is problem solving. And when things are just given to you... you learn nothing. Let's analyse "Undefined variable". "Undefined" means that it hasn't been defined, i.e. not set. A variable is something that holds a value in memory. So, if we put them together; we'll see that it means we've not set a value.
These are BASIC problem solving skills that programmers need. You are not learning anything from what we've shared with you, but instead, you're cuting and pasting it into your code — not understanding what the problem was and how it works.

Please see this resource. It might just help you.

Be a part of the DaniWeb community

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