Jump to content

Recommended Posts

I have looked on the posts and I see several post about this subject but none that have really helped.

 

My problem is inserting the value from my dynamitc drop down.

 

The dropdown menu works great. (See function below) But the post value is null.

 

//category_lists function retrieves data from mysql

 

function BuildCategory()

{

    $category_lists = '              <select name="category_lists">';

    $category_lists .= ('category_lists');

 

    $q = "SELECT id, category FROM category";

     

    $l = connectbg();

    $rs = @mysql_query($q, $l);

    while ($mt = @mysql_fetch_array($rs))

    {

      $category_lists.= "<option value=$mt[id]>$mt[category]</option>";

    }

    disconnectbg($l);

    return $category_lists. '            </select>';

}

 

When the person hits the submit button all of the other input boxes work great and things are entered into the database. This is the only one that will not work.

 

//insert code

 

function BuildInputForm()

{

 

//code before not shown......

 

 

      //calls to functions to create page                         

    $category_lists ='Category List' .BuildCategory();

    $countrylist = 'Country' .  BuildCountry();

 

//code after not shown...

   

}

 

//insert function 

function Input()

{

 

    $product_name=$_POST['product_name'];

    $catalog=$_POST['catalog_id'];

    $price=$_POST['price'];

    $description=$_POST['description'];

    $keywords=$_POST['keywords']; 

    $imageName = $_FILES['userfile']['name'];

    $tmpName  = $_FILES['userfile']['tmp_name'];

    $imageSize = $_FILES['userfile']['size'];

    $imageType = $_FILES['userfile']['filetype'];

    $filePath = $uploadDir . $imageName;

    $country = $_POST['countrylist'];

    $category_lists = $_POST['category_lists'];

    $result = move_uploaded_file($tmpName, $filePath);

 

    if (!$result)

    {

        echo "Error uploading file";

        exit;

    }

        if(!get_magic_quotes_gpc())

            {

              $imageName  = addslashes($imageName);

              $filePath  = addslashes($filePath);

            }

           

             

    $r = connectbg();

    $sql="insert into inventory (category_id, country_id, product_name, catalog_id, price, description, keywords, image) values ('$category_lists','$country','$product_name', '$catalog', '$price', '$description','$keywords','$filePath')";

 

    $res=mysql_query($sql, $r) or die (mysql_error());

    disconnectbg();

   

  }

 

If anyone can see why I can't get the value of the category_lists drop down menu please let me know.

 

Thank you!

$_POST['category_lists'] should be working fine adding a [0] will make no difference..

 

What you need to to is check what variables are being posted across

 

put this at the top of the page that is getting the $_POST data;

 

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

That will show you every $_POST variable being sent to the script..I am thinking that the $_POST['category_lists'] isnt being sent across..

A select menu only returns one value... you may be confusing checkboxes or radio buttons.

 

$_POST['year'];

 

Will return the selected item from a dropdown called "year"

 

$_POST['year'][0];

 

will also work, but is not needed.

Okay I made a couple of changes yet I am still not getting the value to pass through.

 

At a complete loss here.

 

I have posted all of the code I have to see if maybe someone can see where I am missing the passing of the value for catagory_lists.

 

<?php

include("lib/common.lib.php");

$pagetitle = "Battlegear Toys";

$uploadDir = "../upload/";

 

 

if (isset($_POST['submit']))

  {

    Input();

    echo BuildInputForm();

    exit;

  }

 

echo BuildInputForm();

exit;

 

 

//functions

function Getflags()

{

  $flags = '<table>';

  $r = connectbg();

  $sql="SELECT country_name, flag_image FROM country";

  $res=mysql_query($sql, $r);

    while ($resultset = @mysql_fetch_array($res))

    {

      //  $flags .= ($mt['flag_image']);

      $flags .= '<tr>

            <td>' . $resultset['country_name'] . '</td>

            <td ><img src="' .$resultset['flag_image'].'" /></td>

            </tr>';

            $i += 1;

    }

    $flags .= '</table>';

    disconnectbg($r);

    return $flags;             

}

 

 

//works for showing info

function BuildCategory()

{

    $category_lists = '              <select name="category_lists">';

  // $category_lists .= ('category_lists');

 

    $q = "SELECT id, category FROM category";

     

    $l = connectbg();

    $rs = @mysql_query($q, $l);

    while ($mt = @mysql_fetch_array($rs))

    {

      // $content .= '<option value="'.$mt[id].'">'.$mt['name'].' - '.$mt['description'].'</option>';

        $category_lists.= '<option value="'.$mt[id].'">'.$mt['category'].'</option>';

    }

    disconnectbg($l);

    return $category_lists. '            </select>';

 

  }

 

//works but no value posted either. Figured I would fix the first and then duplicate it to make this one work.

function BuildCountry()

{

    $countrylist = '              <select name="countrylist">

';

    $ountrylist .= BuildOption('', 'countrylist');

   

    $r = connectbg();

    $sql="SELECT id, country_name FROM country";

    $res=mysql_query($sql, $r);

    while ($mt = @mysql_fetch_array($res))

    {

        $countrylist .= BuildOption($mt['country_name'], 'countrylist', $mt['id']);

    }

    disconnectbg($r);

    return $countrylist . '            </select>';

}

 

function BuildInputForm()

{

  $flags = Getflags();   

  if (isset($_POST['reset']))

    {

        // user clicked the clear button, so blow off all the search criteria

        // and redraw the search page

        $_REQUEST['product_name'] = null;

        $_POST['catalog_id'] = null;

        $_POST['price']= null;

        $_POST['description'] = null;

        $_POST['keywords'] = null;

        $_POST['catagory_list'] = null;

        $_POST['countrylist'] = null;

     

    }

                               

 

    $category_lists ='Category List' .BuildCategory();

    $countrylist = 'Country' .  BuildCountry();

   

     

$content .= '<form name="form" method="post" ENCTYPE="multipart/form-data" action="input.php">

<table>

   

    <tr>

        <td>Product Name: <input type="text" name="product_name"></td>

    </tr>

    <tr>

        <td>Catalog ID: <input type="text" name="catalog_id" ></td>

    </tr>

    <tr>

        <td>Price: $<input type="text" name="price" ></td>

    </tr>

    <tr>

        <td>Description: <input type="text" name="description" ></td>

    </tr>

    <tr>

        <td>In Stock: <input type="text" name="in_stock" ></td>

    </tr>

    <tr>

        <td>Keyword: <input type="text" name="keywords" ></td>

    </tr>

    <tr>

        <td > <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> 

            Upload image: <input type="file" name="userfile" id="userfile">

        </td>

    </tr>

    <tr>

        <td>

<input name="submit" value="submit" type="submit"> </td>

      <td>

       

<input name="reset" value="reset" type="submit"> </td>

    </tr>

</table>

</form>';

         

 

    return use_template("templates/page.html",

    array("#pagetitle#", "#content#", "#category_lists#", "#countrylist#" , "#flags#"),

    array($pagetitle, $content, $category_lists, $countrylist, $flags) );   

}

 

function Input()

{

 

    $product_name=$_POST['product_name'];

    $catalog=$_POST['catalog_id'];

    $price=$_POST['price'];

    $description=$_POST['description'];

    $keywords=$_POST['keywords']; 

    $imageName = $_FILES['userfile']['name'];

    $tmpName  = $_FILES['userfile']['tmp_name'];

    $imageSize = $_FILES['userfile']['size'];

    $imageType = $_FILES['userfile']['filetype'];

    $filePath = $uploadDir . $imageName;

    $country = $_GET['countrylist'];

  $category_lists = $_POST['category_lists'];  

 

  echo "<pre>";

    print_r($_POST);

    echo "</pre>";

 

    //$category = ;

    $result = move_uploaded_file($tmpName, $filePath);

 

    if (!$result)

    {

        echo "Error uploading file";

        exit;

    }

        if(!get_magic_quotes_gpc())

            {

              $imageName  = addslashes($imageName);

              $filePath  = addslashes($filePath);

            }

           

             

    $r = connectbg();

    $sql="insert into inventory (category_id, country_id, product_name, catalog_id, price, description, keywords, image) values ('$category_lists','$country','$product_name', '$catalog', '$price', '$description','$keywords','$filePath')";

    $res=mysql_query($sql, $r) or die (mysql_error());

    disconnectbg();

   

  }

 

 

?>

 

this function call - BuildCategory()  returns a complete <select>  dropdown

no problems there.

 

this function call - BuildInputForm()  should echo out whatever BuildCategory()

returned. We need to see the missing code for BuildInputForm() where it does the acutal echoing.

You hit the nail on the head!!! It is working! I did not see that I never called the info into the form!

 

No wonder there was no post vaule.

 

I added this bit of code into the form and did a couple of tweeks to the function and I am getting data and inserting it into mysql! yes! Thank you for spotting that!

 

 

  <tr>

    <td> Category List: <select name="category_lists">

    <option value='.$category_lists.'</option>

    </select> </td>

    </tr>

    <tr>

    <td> Country: <select name="countrylist">

    <option value='.$countrylist.'</option>

    </select> </td>

 

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.