View Full Version : Why I Am Not Able To Pass The Value Of Input Type File

11-08-2012, 08:54 PM
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 -

<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" />
And this is my PHP code-

mysql_connect($host, $user, $pass) OR DIE (mysql_error());
mysql_select_db ($db) OR DIE ("Unable to select db".mysql_error());
echo '<p>Please select a file</p>';
echo $image;
echo "File Uploaded";
echo $image;

Where I am making mistake ??? Please guide me.

11-08-2012, 08:58 PM
IMAGE ends up in the $_FILES array and not in the $_POST array.

11-08-2012, 08:58 PM
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'].

11-08-2012, 09:03 PM
Sorry I have it I missed to show it in the code
<input type="submit" value="Confirm" name="confirm" />

11-08-2012, 09:14 PM
Then how can I send the value to another PHP page

11-08-2012, 10:10 PM
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.

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).