Jump to content

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


vishalonne

Recommended Posts

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 -

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

The name of the file itself example: name --> picture.jpg <-- name

 

Now I change my code to like this ->

if(!isset($_FILES["IMAGE"]))
{
echo '<p>Please select a file</p>';
echo $image;
}
else
{
echo "File Uploaded";

 

It is now working showing File Uploaded but notice is still coming

Notice: Undefined index: IMAGE in C:\xampp\htdocs\billing\prodinsert.php on line 11

Now it more problematic

If I don't select any image then also it is showing File Uploaded

 

YES

YES

ITS DONE Thank you Very much

NOTICE GONE BUT I am getting Please select a File message and The name of the File

Here is the modified code -

$code=$_POST['ICODE'];
$descp=$_POST['DESCR'];
$rate=$_POST['RATE'];
$image=$_FILES["IMAGE"]["name"];
if(!isset($_FILES[$image]))
{
echo '<p>Please select a file</p>';
echo $image;
}
else
{
echo "File Uploaded";
echo $image;
......

CAn I just check the this by this way

if(!isset($image))

 

As you suggested me to change

if(!isset($_FILES[$image]))

TO

if(!isset($_FILES["IMAGE"]))

 

now if submit the form without selecting any image file it is showing File Uploaded

You said that was the problem before *facepalm* Ok try this...

 

$code=$_POST['ICODE'];
$descp=$_POST['DESCR'];
$rate=$_POST['RATE'];
$image=$_FILES["IMAGE"]["name"];

if($_FILES["IMAGE"]["error"] > 0) {

echo "Error: " . $_FILES["IMAGE"]["error"] . "<br />";

} else {

if(!isset($_FILES["IMAGE"]["name"]))
{
echo '<p>Please select a file</p>';
}
else
{
echo "File Uploaded";
echo $image;

}

You said that was the problem before *facepalm* Ok try this...

 

$code=$_POST['ICODE'];
$descp=$_POST['DESCR'];
$rate=$_POST['RATE'];
$image=$_FILES["IMAGE"]["name"];

if($_FILES["IMAGE"]["error"] > 0) {

echo "Error: " . $_FILES["IMAGE"]["error"] . "<br />";

} else {

if(!isset($_FILES["IMAGE"]["name"]))
{
echo '<p>Please select a file</p>';
}
else
{
echo "File Uploaded";
echo $image;

}

Thank you for your co operation

After using the code you gave If I select image it it shows "File Uploaded" with the name of the image file

And if I don't select image file it show Error: 4

Can't understand why 4? why not it shows "Please select a file"

Error code 4 means that there was no file uploaded

 

A full list can be found at http://php.net/manua...load.errors.php

 

If you wish to change it simply do:

 

$code=$_POST['ICODE'];
$descp=$_POST['DESCR'];
$rate=$_POST['RATE'];
$image=$_FILES["IMAGE"]["name"];

if($_FILES["IMAGE"]["error"] > 0) {

// create a list of errors here
if($_FILES["IMAGE"]["error"] == "4") {
echo "Please select a file.";
}

} else {

echo "File Uploaded";
echo $image;

}

Error code 4 means that there was no file uploaded

 

A full list can be found at http://php.net/manua...load.errors.php

 

If you wish to change it simply do:

 

$code=$_POST['ICODE'];
$descp=$_POST['DESCR'];
$rate=$_POST['RATE'];
$image=$_FILES["IMAGE"]["name"];

if($_FILES["IMAGE"]["error"] > 0) {

// create a list of errors here
if($_FILES["IMAGE"]["error"] == "4") {
echo "Please select a file.";
}

} else {

echo "File Uploaded";
echo $image;

}

 

Great You are Genius

Thank you very much

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.