Why is my function posting the wrong value?

Posted on 2011-05-01
Last Modified: 2012-05-11
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>

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 = "";
      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?'?
Question by:FairyBusiness
    LVL 27

    Expert Comment

    by:Lukasz Chmielewski
    why mixing the form values ? the method you have chosen should be post.

    Author Comment

    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.
    LVL 82

    Accepted Solution


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

    Open in new window


    Author Closing Comment

    Thanks again ;)

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now