Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Why is my function posting the wrong value?

Hi,  I am trying to post the value of my selection box to figure out which table I needed to put the uploaded files into:

<select name="table">
  <option value="earrings">earrings</option>
  <option value="bracelets">bracelets</option>
<  option value="necklaces">necklaces</option>
</select>

function upload() {
      if((isset($_FILES['image'])) && (!empty($_POST['image']))) {
            if(isset($_GET['edit'])) {
                  $table = $_GET['edit'];
            }
            if(isset($_POST['table'])) {
                  $table = $_POST['table'];
            }
            $image = explode('.',basename($_FILES['image']['name']));
            $image = $image[0];            
            $file = basename($_FILES['image']['name']);      
            $temp_path = $_FILES['image']['tmp_name'];
            $target_path = $table . "/" . $image;
            move_uploaded_file($temp_path, $target_path);
      }
      elseif(isset($_GET['item'])) {
            $image = $_GET['item'];
      }
      else {
            $image = "";
      }
      var_dump($table);
      return $image;
}

If I hit the submit button without putting anything into the first input text field it returns as 0 but if I write something then it posts it as the table name.  How do I get it to stop posting values from the 'name' field and start recognizing the 'table field?'?
0
FairyBusiness
Asked:
FairyBusiness
  • 2
1 Solution
 
Lukasz ChmielewskiCommented:
why mixing the form values ? the method you have chosen should be post.
0
 
FairyBusinessAuthor Commented:
bc I use this function on another page and the way I determine what the table is by whats in the edit in the url.  But for this since its a blank canvas the user could select any table so I need to know which one.
0
 
hieloCommented:
try:



if(isset($_POST['table']) && !empty($_POST['table']) ) {
                  $table = $_POST['table'];
            }
            elseif(isset($_GET['edit']) && !empty($_GET['edit']) ) {
                  $table = $_GET['edit'];
            }

Open in new window

0
 
FairyBusinessAuthor Commented:
Thanks again ;)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now