Q695 Posted May 2, 2013 Share Posted May 2, 2013 How would I write the following if statement properly to make sure there aren't any errors with the file? Quote Link to comment Share on other sites More sharing options...
requinix Posted May 2, 2013 Share Posted May 2, 2013 if ($_FILES['creature_image']['error'] == 0) { Quote Link to comment Share on other sites More sharing options...
Q695 Posted May 3, 2013 Author Share Posted May 3, 2013 (edited) Why was it the double equals that time, but the previous time it was the single equals? Edited May 3, 2013 by Q695 Quote Link to comment Share on other sites More sharing options...
requinix Posted May 3, 2013 Share Posted May 3, 2013 When? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 3, 2013 Share Posted May 3, 2013 (edited) i'm not sure what previous time you are referring to, but for the line of code in this thread, DavidAM told you in your previous thread that one equal sign means that you are making an ASSIGNMENT, not a comparison - 1) A single equals-sign is ASSIGNMENT, it takes two to COMPARE: an argument can be made that you need === (three equal signs, a value and type match) for this line of code, since your image uploader script isn't testing if the $_FILES array is even set/not-empty. when $_FILES is empty due to an error or an upload form has not been submitted (your code isn't testing if any form was submitted), an empty $_FILES array will match a zero using two == signs. using three === (a value and type check), will only be successful if the $_FILES array is not empty and the ['error'] is a zero value. FYI, why you need to learn the meaning of the code - one = sign is an assignment operator i.e $var = some_value;. when used in a conditional test - if($var = some_value) ... while($var = some_value) the assignment is made and the value that was assigned is used in the conditional test. two == signs is an equal value test (the types can be different i.e null/empty is == to a 0.) three === signs is an exact value test (the value and types must be the same i.e. null/empty is not === 0.) Edited May 3, 2013 by mac_gyver Quote Link to comment 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.