Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Jackie Jen
Jackie Jen
2,723 Points

<input type="file" name="attachment"> warning Undefined index: attachment

<form action="1st_page.php"  method="post" >
<input type="file" name="attachment" id="attachment" >
<input class="button" type="submit" name="submit" value="Submit" />

below is 1st_page.php

$_SESSION['attachment'] = trim ($_POST['attachment']);

At 1st the input type =file i would like to allow user to attach file or picture whenever they like. But when user did not upload the file which mean the $_POST['attachment'] doest not have any data/string therefore i have warning on 1st-page.php Undefined index: attachment.

How can i get rid of this warning?

2 Answers

do it like this <?php if(isset($_POST['attachment'])) { $_SESSION['attachment'] = trim ($_POST['attachment']); } ?>

Try the above and see if it works.

Jackie Jen
Jackie Jen
2,723 Points

why i didn't think of that... anyway thanks a lot andreas