Jump to content

Recommended Posts

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'];

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.