TeroYukio Posted July 22, 2010 Share Posted July 22, 2010 Okay so here is my problem, I have an error to be set if the file type isn't specified. if ($type == 0 || !in_array($type,array('sounds','textures','ui'))) { $errors[] = "Please select a valid type!"; } Seems right...right? Well it gets $type from my form: echo "<tr><td>Type</td><td><select name=\"type\"> <option value=\"0\">--Select One--</option> <option value=\"sounds\">Sound Mod</option> <option value=\"textures\">Texture Mod</option> <option value=\"ui\">User Interface Mod</option> </select></td></tr>\n"; The problem is I choose Sound Mod from the options and the error pops up after I click submit saying I didn't specify or choose a type of file. Anyone know why? $type = $_POST['type']; Link to comment https://forums.phpfreaks.com/topic/208508-not-identifying-a-positive-value-in-the-array-from-a-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 22, 2010 Share Posted July 22, 2010 The problem is because you are comparing $type with a numeric value using a loose comparison (==.) Php converts the value in $type to a number in this case, which results in a zero being used for the comparison. You actually only need to use if(!in_array($type,array('sounds','textures','ui')) because the zero value is not in that array as well. Link to comment https://forums.phpfreaks.com/topic/208508-not-identifying-a-positive-value-in-the-array-from-a-form/#findComment-1089430 Share on other sites More sharing options...
TeroYukio Posted July 22, 2010 Author Share Posted July 22, 2010 Thank you good sir, it now works without flaw! SOLVED Link to comment https://forums.phpfreaks.com/topic/208508-not-identifying-a-positive-value-in-the-array-from-a-form/#findComment-1089431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.