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:
]) && !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:

  <form action="upload.php" method="post" id="uploadform" name="uploadform" enctype="multipart/form-data">  
    <label id="filelabel" for="fileselect">Choose the Pictures</label>
    <input type="file" id="fileselect" class="fileuplaod" name="uploads[]" multiple />
    <span class="text">Exist Album</span><br />
    <select id="existAlbum" name="existAlbum" size="1">
      <option value="noAlbum">SELECT ALBUM</option>       
    </select>
    <span class="text">OR</span>
    <span class="text">New Album</span><br />
    <input id="newAlbum" name="newAlbum" type="text" maxlength="20" placeholder="ALBUM NAME"/>
    <input type="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:

 if isset($_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"