Notice: Undefined index: PHP 5 What causes this?

I realise it’s just a notice but this suggests to me that I should sort out the problem, notice or not. This notice originates from a form which submits to a file which processes the fields and then sends.

First off then, these are the notices;

Notice: Undefined index: advice in D:\***\ hanks.php on line 10

Notice: Undefined index: ukeurope in D:\***\ hanks.php on line 30

Notice: Undefined index: usacanada in D:\***\ hanks.php on line 31

Notice: Undefined index: other in D:\***\ hanks.php on line 32

And here is the corresponding code in the processing page;

10 if ( $_POST[‘advice’]) {

30 $ukeurope = $_POST[‘ukeurope’];

31 $usacanada = $_POST[‘usacanada’];

32 $other = $_POST[‘other’];

I’ve read somewhere that it’s due to me not doing this:

$advice = $_POST[‘advice’];

Would this be the case do you think?

Hope someone can help with this as I’d really like to do this correctly!

Rob

You are referencing $_POST[‘advice’] when $_POST[‘advice’] isn’t set.
Try doing if(isset($_POST[‘advice’])) { … }

Ah yes, I see what you mean, logical really! I’ll make the changes you suggested. Thanks Mark, and thanks for your extremely quick reply!

Rob

Hello guys i have seached the forum for this undefined index error but my case seems different as I ran the following form:

target_path = “uploads/”;
$target_path = $target_path.basename($_FILES[‘uploadedFile’][‘name’]);

if(move_uploaded_file($_FILES[‘uploadedFile’][‘tmp_name’], $target_path)){

echo "The file". basename($_FILES['uploadedFile']['name']). "has been uploaded";

}
else{
echo “There was an error uploading the file, please try again!”;
}
?>
The error: line 23 is the highlited line above.
Notice: Undefined index: uploadedFile in C:\wamp\www\saterisk\uploadmanager.php on line 23.

Could someone please help? Thanks

try like this::
$target_path = $target_path.basename($HTTP_POST_FILES[‘uploadedFile’][‘name’]);

Do a print_r of $_FILES and see what it contains.

And please, next time don’t bump a 4 year old thread to ask your question. Create a new thread, and if needed link to the old one.

I have tried the suggestion and had the error below:

Notice: Undefined variable: HTTP_POST_FILES in C:\\wamp\\www\\saterisk\\uploadmanager.php on line 23 
Call Stack 
# Time Memory Function Location 
1 0.0013 376352 {main}( ) ..\\uploadmanager.php:0 

Guido, I have noted your point.

HTTP_POST_FILES was deprecated in php 4.1.x
use $_FILES instead

edit

Just reread your original post where you are indeed using $_FILES!

OK, Check that in your form your file input field is called uploadedFile
ie
<input type=“file” name=“uploadedFile” />

HTTP_POST_FILES is no longer valid, IIRC.

Check out the information (array keys) available to you in the $_FILES superglobal in the manual:slight_smile:

:slight_smile:

many thanks. my input file name was “uploadedfile” while i was using “uploadedFile” in my php script. Apologies for bothering you for this mistake of mine. Maybe i needed a third eye.

dont apologise, we have all done it at some time or another (and still do!)
Glad you got it sorted :tup: