Hmmm... I've got an image script going, where the user uploads a file and it does its thing to it. However, when I try and add a text input field and retrieve the data via $_post it generates the following error: the code is as follows: <form id="Upload" action="upload.processor.php" enctype="multipart/form-data" method="post"> <h1> Upload form </h1> <p> <label for="file">File to upload:</label> <input id="file" type="file" name="file"> </p> <p> <label for="text">Enter text:</label> <input type="text" name="userText"> </p> <p> <label for="submit">Press to...</label> <input id="submit" type="submit" name="submit" value="Upload me!"> </p> </form> Code (markup): while the php code generating the error is simply $userText = $_POST["userText"]; Code (markup): Can anyone advise me on how to retrieve the text data too?
It happens because _POST["userText"]; is not seted. It's not error, it's notice. Use this: if (isset($_POST["userText"])) $userText = $_POST["userText"]; else echo "blah-blah"; PHP:
I would stress that you must test all user input before doing anything with it. In this case $userText must have a safe, default value. The post value needs to be tested as shown by vdd or some other technique. Then you need to make sure the value itself can be safely displayed to the screen or placed into a database. I also try to track down all such warnings and fix them. They point to incomplete code and obscure more important warnings and errors. An application's error log should contain real errors and be viewed as an actionable document -- even if it is for your own site. Remember, logs swallow hard drive space whole.
Many thanks for your help guys And yeah, I'm currently sanitising the user input and going through the error logs (I tend to delete the file each time an error is fixed, so I have a clean log of errors to focus on each time the log gets generated).