wildbuddha Posted April 2, 2013 Share Posted April 2, 2013 Hi everyone. Thanks, in advance, for any and all help! I'm sure there's something simple I'm missing as I'm very new to PHP. function uploadAttachment() { if(isset($_POST['submitAttachment'])) { if ($File) { copy ($File, "$File_name"); $db_hostname = "localhost"; $db_username = "root"; $db_password = ""; $db_name = "justinalba_module3_db"; $dbc = @mysqli_connect($db_hostname, $db_username, $db_password, $db_name) or die("Unable to connect to MySQL"); $username = $_POST['userName']; $id=$_POST['id']; $sql="UPDATE user SET avatarURL='$File_name' WHERE name_username='$username' AND id='$id'"; $query=mysqli_query($dbc,$sql) or die(); $sql2="SELECT * FROM user WHERE name_username='$username' AND id='$id'"; $query2=mysqli_query($dbc,$sql2) or die(); if($query) { echo "You uploaded the following photo:"; echo "<img src=\""; echo $File_name; echo "\" width=\"400px\">"; unlink ($File); } else { echo "You did not upload a file."; } } } } The above code is giving me an error: "Notice: Undefined variable: File in /Users/justinalba/Sites/php-class/module3/functions.php on line 257" How come the variable can be found on line 255 but not 257? Do I need to declare $File as something? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/276440-simple-image-uploader-gone-wrong/ Share on other sites More sharing options...
Psycho Posted April 2, 2013 Share Posted April 2, 2013 Line 257 in your code above is this { Which is between the two lines that reference $File. Are you sure the error is not on the first instance? Try putting in some echo statements to verify echo "Before the if()<br>\n"; if ($File) { echo "After the if()<br>\n"; copy ($File, "$File_name"); echo "After the copy()<br>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/276440-simple-image-uploader-gone-wrong/#findComment-1422480 Share on other sites More sharing options...
wildbuddha Posted April 2, 2013 Author Share Posted April 2, 2013 You're right! "Before the If" was displayed after inserting the code you gave me. That means that's the undefined variable? Thanks btw Quote Link to comment https://forums.phpfreaks.com/topic/276440-simple-image-uploader-gone-wrong/#findComment-1422481 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.