Skip to content Skip to sidebar Skip to footer

Can't Get The $_post Variable

It should be a multiple upload form for pictures I get the HTML Code for a Upload-Form:

EDIT

Since the user only has to supply one or the other, you should use the following to set your variables:

$existsAlbum = (isset($_POST['existAlbum']) && !empty($_POST['existAlbum'])) ? $_POST['existAlbum'] : 'defaultValue';
$newAlbum = (isset($_POST['newAlbum']) && !empty($_POST['newAlbum'])) ? $_POST['newAlbum'] : 'defaultValue';

One important thing to note is that Internet Explorer does not support the placeholder attribute.

EDIT 2

Here is my quick test page that worked test.php:

<formaction="upload.php"method="post"id="uploadform"name="uploadform"enctype="multipart/form-data"><labelid="filelabel"for="fileselect">Choose the Pictures</label><inputtype="file"id="fileselect"class="fileuplaod"name="uploads[]"multiple /><spanclass="text">Exist Album</span><br /><selectid="existAlbum"name="existAlbum"size="1"><optionvalue="noAlbum">SELECT ALBUM</option></select><spanclass="text">OR</span><spanclass="text">New Album</span><br /><inputid="newAlbum"name="newAlbum"type="text"maxlength="20"placeholder="ALBUM NAME"/><inputtype="submit"value="Submit"></form>

upload.php

<pre><?php print_r($_POST); ?><?php print_r($_FILES); ?></pre>

results

Array
(
    [existAlbum] => noAlbum
    [newAlbum] => 
)
Array
(
    [uploads] => Array
        (
            //Contents here
        )
)

Solution 2:

Try if the value existAlbum get set, because it won't return any value if you there is nothing picked. You could give the existAlbum picker a default='1' or something:

ifisset($_POST['existAlbum']){
        echo'yes';
 }
 else{
      echo'no';
 }

I think that there is something wrong with the rule enctype="multipart/form-data". Try to just remove this, it should be set automatically by your browser.

Solution 3:

You have no value for the option select album, even if you don't intend that option to be used give it a value such as 0 so that it will always be set in the POST variables.

<option value="0">SELECT ALBUM</option>
<option value="some album">Some Album</option>
...

Solution 4:

If select is not picked you will not get it at all (you expect it to be empty, which is not true). You have to check first

$exist_album = isset($_POST['existAlbum']) ? $_POST['existAlbum'] : '<DEFAULT VALUE>';

and same for checkbox.

The newAlbum thing should work as text inputs are always there. See

print_r($_POST);

to see what's really in there, and in my case it is - on "empty" submit I get:

Array
(
    [existAlbum] => SELECT ALBUM
    [newAlbum] => 
)

BTW: you should use <?php rather than <?PHP.

Solution 5:

print $_POST Array using print_r($_POST); Make sure your form action is correct

<form action="upload.php" method="post"id="uploadform" name="uploadform" enctype="multipart/form-data">

Post a Comment for "Can't Get The $_post Variable"