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 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Why I Am Not Able To Pass The Value Of Input Type File

    Hi
    I just wan to to pass the value of Input Type File html tag to a 2nd PHP page where I will insert the image in mysql but I am always getting a notice and isset() is not getting the $_FILE('IMAGE').
    Here is the notice - Notice: Undefined index: IMAGE in C:\xampp\htdocs\billing\prodinsert.php on line 11
    This is my HTML TAGS -
    Code:
    <body> 
    <hr /> 
    <form id="form1" name="form1" method="post" action="prodinsert.php" enctype="multipart/form-data"> 
    <input name="ICODE" type="text" size="10" maxlength="6" /> 
    <input name="DESCR" type="text" size="50" maxlength="45" /> 
    <input name="RATE" type="text" size="10" maxlength="9" /> 
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> 
    <input name="IMAGE" type="file" /> 
    </form>
    And this is my PHP code-
    PHP Code:
    <?php 
    $host
    ="localhost"
    $user="root"
    $pass=""
    $db="bill"
    mysql_connect($host$user$pass) OR DIE (mysql_error()); 
    mysql_select_db ($db) OR DIE ("Unable to select db".mysql_error()); 
    $code=$_POST['ICODE']; 
    $descp=$_POST['DESCR']; 
    $rate=$_POST['RATE']; 
    $image=$_POST['IMAGE']; 
    if(!isset(
    $_FILES[$image])) 

    echo 
    '<p>Please select a file</p>'
    echo 
    $image

    else 

    echo 
    "File Uploaded"
    echo 
    $image
    }
    Where I am making mistake ??? Please guide me.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    IMAGE ends up in the $_FILES array and not in the $_POST array.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Where's the submit button on the form? You require that in order to post the data using an HTML form.
    Otherwise, there will be no $_POST['IMAGE']. It will be under $_FILES['IMAGE'].

  • #4
    New Coder
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Sorry I have it I missed to show it in the code
    Code:
    <input type="submit" value="Confirm" name="confirm" />

  • #5
    New Coder
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Then how can I send the value to another PHP page

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by vishalonne View Post
    Then how can I send the value to another PHP page
    You can change the action attribute of the form to control what script is posted to. Currently it goes to prodinsert.php.

    Edit:
    Wait, do you mean send it from the form to a different script, or send the data from this script to another? If the latter, you need to use something more manual such as curl, sockets, or another method such as soap protocols. If this secondary script is owned on the same server, it can be included in and it will have access to all the variables available at the scope in which it was included (including the $_FILES superglobal).


  •  

    Posting Permissions

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