PHP beginner question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben

    #1

    PHP beginner question

    Hello,

    I am currently learning PHP, and I have a problem with some variables.
    On the first page (choix.php), there is a form that lists product
    categories.This is the concerned part:

    echo "<form action='dc.php' method='post'>
    <select name='p_type2' value='p_type2' > \n";

    while ($ligne = mysql_fetch_arr ay($result))
    { extract($ligne) ;
    echo "<option value='$p_type2 '>$p_type\n";
    }
    echo "</select>\n";

    echo "<input type='submit'".
    "value=\"Choisi ssez un type de produit\"></form>\n";?>

    On the other page, dc.php , the program has to list the products in
    the category chosen by the user above. I want the product chosen to be
    inserted in

    $typeproduit = "$HTTP_POST_VAR S[$p_type2]";

    where $type_produit is the product chosen. (When i write, for
    example,:

    $type_produit = "CPU";

    the program works. But it doesn't work when I put a variable. Can you
    help me ?

    Thank you


    Ben C.
  • MeerKat

    #2
    Re: PHP beginner question

    Ben wrote:

    [snip][color=blue]
    > $typeproduit = "$HTTP_POST_VAR S[$p_type2]";[/color]

    Try:
    $typeproduit = $HTTP_POST_VARS[$p_type2];

    --
    MeerKat

    Comment

    • Andy Hassall

      #3
      Re: PHP beginner question

      On 23 Sep 2003 13:40:14 -0700, microben@hotmai l.com (Ben) wrote:
      [color=blue]
      > <select name='p_type2' value='p_type2' > \n";[/color]

      The select element does not have a value attribute.
      [color=blue]
      >while ($ligne = mysql_fetch_arr ay($result))
      >{ extract($ligne) ;
      > echo "<option value='$p_type2 '>$p_type\n";
      >}
      >echo "</select>\n";
      >
      >echo "<input type='submit'".
      > "value=\"Choisi ssez un type de produit\"></form>\n";?>
      >
      >On the other page, dc.php , the program has to list the products in
      >the category chosen by the user above. I want the product chosen to be
      >inserted in
      >
      >$typeproduit = "$HTTP_POST_VAR S[$p_type2]";[/color]

      $typeproduit = $_POST['p_type2'];

      --
      Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
      Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

      Comment

      • Ben

        #4
        Re: PHP beginner question

        Andy Hassall <andy@andyh.co. uk> wrote in message news:<vdl1nv4jl oiksmv6con6bjoa n7qgdn2q8e@4ax. com>...[color=blue]
        > On 23 Sep 2003 13:40:14 -0700, microben@hotmai l.com (Ben) wrote:
        >[color=green]
        > > <select name='p_type2' value='p_type2' > \n";[/color]
        >
        > The select element does not have a value attribute.[/color]

        You mean I should remove the value='p_type2' > /n"; ?
        or should I put another value ?

        Thank you for your answers guys.

        Comment

        • Pedro

          #5
          Re: PHP beginner question

          Ben wrote:[color=blue]
          >Andy Hassall <andy@andyh.co. uk> wrote in message news:<vdl1nv4jl oiksmv6con6bjoa n7qgdn2q8e@4ax. com>...[color=green]
          >> On 23 Sep 2003 13:40:14 -0700, microben@hotmai l.com (Ben) wrote:
          >>[color=darkred]
          >> > <select name='p_type2' value='p_type2' > \n";[/color]
          >>
          >> The select element does not have a value attribute.[/color]
          >
          >You mean I should remove the value='p_type2' > /n"; ?
          >or should I put another value ?[/color]

          You should remove the value attribute from the select

          AFAIK the select construct is like this:

          <select name="combo">
          <option value="v1">text 1</option>
          <option value="v2">text 2</option>
          <!-- ... -->
          <option value="vn">text n</option>
          </select>

          And you check it in php with $_POST['combo'] or $_GET['combo']
          according to the method used for the form.

          The text1, text2, ..., textn are only visible to the browser; you will
          not have access to them in the script the form is submitted to --
          often they are the same as the v1, v2, ..., vn but that is not
          mandatory.


          --
          I have a spam filter working.
          To mail me include "urkxvq" (with or without the quotes)
          in the subject line, or your mail will be ruthlessly discarded.

          Comment

          • Geoff Berrow

            #6
            Re: PHP beginner question

            I noticed that Message-ID: <5he4nvca5f74c0 3l7hqg3uss7fd4s krd8j@4ax.com>
            from Pedro contained the following:
            [color=blue]
            ><select name="combo">
            > <option value="v1">text 1</option>
            > <option value="v2">text 2</option>
            > <!-- ... -->
            > <option value="vn">text n</option>
            ></select>
            >
            >And you check it in php with $_POST['combo'] or $_GET['combo']
            >according to the method used for the form.
            >
            >The text1, text2, ..., textn are only visible to the browser; you will
            >not have access to them in the script the form is submitted to --
            >often they are the same as the v1, v2, ..., vn but that is not
            >mandatory.[/color]

            But if you leave out the value="", text1, text2 etc become the values.
            --
            Geoff Berrow
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            Working...