Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6824627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:55:26+00:00 2026-05-26T21:55:26+00:00

I have spent the last 3 hours trying to get this code working. I

  • 0

I have spent the last 3 hours trying to get this code working. I don’t understand why it’s telling me that ‘id’ is undefined.

My aim was to be able to update pictures in my little table. So far I can’t update it because of the error I’m getting.

Here’s the whole code:

    <?php

    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Edit Details</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5">

    </head>
    <body>

        <div id="content">
          <div class="about">
             <h2>Modify Entry</h2>

          <div class="main">                         

                <?php
                 global $record;
                 global $oldPic2;
                 global $oldPic3;
                 global $id;

                 $con = mysql_connect('localhost', 'root', '') or die(mysql_error()) ; 

                if (!$con){
                   die('Could not connect: ' . mysql_error());
                }
                  mysql_select_db("peopledb", $con);

                 if(!isset($_POST['submit'])){
                     $q = "SELECT * from image_table WHERE id = $_GET[id]";
                     $result = mysql_query($q) or die(mysql_error());
                     $record = mysql_fetch_array($result);

                     $oldPic2 =  $record['img2'];
                     $oldPic3 =  $record['img3'];

                }
           ?>

   <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
   <div style="font-weight:bold; margin-top:5px; border: 1px solid #C6CFE1; padding:5px 0 5px 5px;background-color: #F5F2EE;">

    <table cellspacing="6">
        <tr>    
           <td>
             <b>Name:</b>
          </td>
            <td>
            <input type="text" name="name" id="name" value ="<?php echo $record['name']; ?>" /> 
            </td>

            <td>
               <b>Image 1:</b>
           </td>
           <td>
            <input type="text" name="breed" id="breed" value ="<?php echo $record['img']; ?>" /> 
           </td>

           <td>
             <b>Image 2:</b>
           </td>
           <td>
             <input type="text" name="img2" id="img2" size="16" value ="<?php echo $record['img2']; ?>" /> 
           </td>
           </tr>


           </table>

        <table>
            <tr>
             <td style="padding-right: 15px;">
            <img src="test/<?php echo $record['img']; ?>" width="45" height="40" />  
             </td>
            <td>
            <input type="file" name="pic" value="Browse">
            </td>
        </tr>
        <tr>
        <td>
        <img src="test/<?php echo $record['img2']; ?>" width="45" height="40" /> 
         </td>
        <td>
        <input type="file" name="pic2" value="Browse">
        </td>
        </tr>


        <tr>
         <td>
                            <img src="test/<?php echo $record['img3']; ?>" width="45" height="40" /> 
                       </td>
                       <td>
                            <input type="file" name="pic3" value="Browse">
                       </td>
                    </tr>

                    </table>

                            <p />
                            <b>Description:</b> <br />
                            <script>edToolbar('description'); </script>
                            <textarea rows="10" cols="60" id="description" name="description" align="center"><?php echo $record['description']; ?></textarea><br /><br />                                               
                            <br /><br />                         
                            <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
                            <input type="submit" name="submit" value="Submit Update" />
                </div>
            </form>
      <?php
                    if(isset($_POST['submit'])){                


                            $pic =($_FILES['pic']['name']); 

                            $pic2 =($_FILES['pic2']['name']);  
                            $pic3 =($_FILES['pic3']['name']);  

                            if( $pic == ""){
                                    $pic = $record['img']; 
                            }   
                            if( $pic2 == ""){
                                    $pic2 = $oldPic2; 

                            }    

                            if( $pic3 == ""){
                                    $pic3 = $oldPic3; 

                            }    


                            $id = $_GET[id];
                            $q = "UPDATE image_table SET `name`='$_POST[name]', 
                            `description`='$_POST[description]',
                            `img`= '$pic',
                            `img2`= '$pic2',
                            `img3`='$pic3',
                             WHERE id = $_POST[id]";
                             mysql_query($q) or die(mysql_error());                             

                            $target = "test/"; 
                            //$target1 = $target."/".$record['id'];

                            $target1 = $target . basename( $_FILES['pic1']['name']); 
                            $target2 = $target . basename( $_FILES['pic2']['name']); 
                            $target3 = $target . basename( $_FILES['pic3']['name']); 

                            if(move_uploaded_file($_FILES['pic']['tmp_name'], $target1)) { 

                            }
                            if(move_uploaded_file($_FILES['pic2']['tmp_name'], $target2)) { 

                            }if(move_uploaded_file($_FILES['pic3']['tmp_name'], $target3)) { 

                            echo "Image updated successfully";  
                    }else{
                            echo"There was an error updating your picture";
                    }

                }
            ?>                                  
                    </div>


                    </div>
                    <div class="list">

                    </div>

            </div>

        </body>

    </html>

Any help would be highly appreciated.

Note: The select statement works, but it’s the when I try updating that it throws the error message. Id underfined 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:55:27+00:00Added an answer on May 26, 2026 at 9:55 pm

    I finally got t working. Declaring the id as global did the trick. Previously, the id was not available outside the block where it was assigned a value.

    A nice way to learn new things 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent the last several hours trying to get this to work and
I have spent the last 4 hours trying to get my iPad to run
I've spent the last 2 hours trying to find a solution for this and
I just spent the last 3 hours trying to figure out this error. I
Urgh, I have spent the last couple of hours on this now. I normally
I've spent the last few hours trying to find the solution to this question
I've spent the last three hours trying to get a simple Twitter status update
I've spent about 10 hours trying to find this bug that was causing my
So I just spent the last few hours pouring over code trying to figure
I have spent the last several years fighting tooth and nail to avoid working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.