Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2011
    Posts
    201
    Thanks
    12
    Thanked 26 Times in 26 Posts

    Undefined Index mysql query

    I am trying to implement a upload script can you please help me debug my errors? DB users TABLE images.

    Notice: Undefined index: img in C:\wamp\www\workfun\myaccount.php on line 64

    PHP Code:
    $result mysql_query("SELECT * FROM images WHERE img='".$_GET['img']."'"); 


    PHP Code:
    <?php 


    //connect to database. Username and password need to be changed 
    mysql_connect("localhost""root""Superfad11"); 

    //Select database, database_name needs to be changed 
    mysql_select_db("users"); 

    if (!
    $_POST['uploaded']){ 
    //If nothing has been uploaded display the form 
    ?> 

    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"  
    ENCTYPE="multipart/form-data"> 
    Upload:<br><br> 
    <input type="file" name="image"><br><br> 
    <input type="hidden" name="uploaded" value="1"> 
    <input type="submit" value="Upload"> 
    </form> 

    <? 
    }else{ 
    //if the form hasn't been submitted then: 

    //from here onwards, we are copying the file to the directory you made earlier, so it can then be moved  
    //into the database. The image is named after the persons IP address until it gets moved into the database 

    //get users IP 
    $ip=$REMOTE_ADDR

    //don't continue if an image hasn't been uploaded 
    if (!empty($image)){ 

    //copy the image to directory 
    copy($image"./temporary/".$ip.""); 

    //open the copied image, ready to encode into text to go into the database 
    $filename1 "./temporary/".$REMOTE_ADDR
    $fp1 fopen($filename1"r"); 

    //record the image contents into a variable 
    $contents1 fread($fp1filesize($filename1)); 

    //close the file 
    fclose($fp1); 

    //encode the image into text 
    $encoded chunk_split(base64_encode($contents1));  

    //insert information into the database 
    mysql_query("INSERT INTO images (img,data)"."VALUES ('NULL', '$encoded')"); 

    //delete the temporary file we made 
    unlink($filename1); 


    //end 

    ?>
    Last edited by SeattleMicah; 10-12-2012 at 10:55 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This query isn't in here anywhere.
    The error is simple: you have no img offset in your $_GET superglobal. Since you didn't post that code, we can't help you with that.

    On the other hand, this other code is ancient. It relies on register globals which are now gone. $REMOTE_ADDR and $image will not exist for use as of 5.4, and will only exist if register_globals are explicitly enabled as of 4.2.0.
    Code wise there is no reason to move or copy this file if you are storing it in a db. Simply read and passthru it from the temporary location (that is, where $_FILES is stored, not where you created the ./temporary/).

  • #3
    Regular Coder
    Join Date
    Dec 2011
    Posts
    201
    Thanks
    12
    Thanked 26 Times in 26 Posts
    sorry for wasting both of our time, im going to find a better script.

  • #4
    Regular Coder
    Join Date
    Dec 2011
    Posts
    201
    Thanks
    12
    Thanked 26 Times in 26 Posts
    every upload script I use I get the error

    Notice: Undefined index: ______

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by SeattleMicah View Post
    every upload script I use I get the error

    Notice: Undefined index: ______
    That error is caused by trying to access an array element that doesn't exist, such as this line:
    PHP Code:
    if (!$_POST['uploaded']){ 
    That should be checked like this:
    PHP Code:
    if (!isset($_POST['uploaded']) || !$_POST['uploaded']){ 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •