Php Form and Array

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

    Php Form and Array

    Dear all,

    I created the following php form.

    <FORM METHOD="POST" ACTION="prova.p hp">
    <b>Combinatio n</b><br><br>
    Element 1: <INPUT NAME="el1" TYPE="TEXT">
    <BR>
    Element 2: <INPUT NAME="el2" TYPE="TEXT">
    <br>
    <INPUT TYPE="SUBMIT" VALUE"Submit">
    </FORM>
    <br>
    Combination<br> <br>

    <?php
    $combination[] = ($_REQUEST["el1"].$_REQUEST["el2"]);
    print_r($combin ation);
    $combinations[] = $combination;
    print_r($combin ations);
    ?>

    When I fill the two text fields of the form in the browser, the inserted
    text is included in the array $combination and then $combination is
    included in the array $combinations.
    When I reload the page, I fill again the two text fields and the new
    inserted text overwrites the old inserted text. This is a problem.
    I'd like that the array "combinatio ns" includes both the old inserted
    text and the new inserted text, but I don't know how to do this.
    Can you help me please?
    Many thanks.

    Best,
    Nico
  • no@emails.thx

    #2
    Re: Php Form and Array

    On Tue, 05 Dec 2006 11:53:21 +0100, Nico <noemail@noemai l.comwrote:
    >Dear all,
    >
    >I created the following php form.
    >
    ><FORM METHOD="POST" ACTION="prova.p hp">
    ><b>Combination </b><br><br>
    >Element 1: <INPUT NAME="el1" TYPE="TEXT">
    ><BR>
    >Element 2: <INPUT NAME="el2" TYPE="TEXT">
    ><br>
    ><INPUT TYPE="SUBMIT" VALUE"Submit">
    ></FORM>
    ><br>
    >Combination<br ><br>
    >
    ><?php
    $combination[] = ($_REQUEST["el1"].$_REQUEST["el2"]);
    print_r($combin ation);
    $combinations[] = $combination;
    print_r($combin ations);
    >?>
    >
    >When I fill the two text fields of the form in the browser, the inserted
    >text is included in the array $combination and then $combination is
    >included in the array $combinations.
    >When I reload the page, I fill again the two text fields and the new
    >inserted text overwrites the old inserted text. This is a problem.
    >I'd like that the array "combinatio ns" includes both the old inserted
    >text and the new inserted text, but I don't know how to do this.
    >Can you help me please?
    >Many thanks.
    Hi Nico

    Sounds like you are trying ot make the data persist between page
    refreshes. The best way to handle this is to use 'sessions' and make
    $combinations into a session variable like $_SESSION['combinations'][]
    Just start your PHP code with session_start() ; and then manipulate
    your array :o)

    Chris R.

    Comment

    • Nico

      #3
      Re: Php Form and Array

      In article <a1man2528cqd1e oj0ann38ij809rc lec5q@4ax.com>, no@emails.thx
      wrote:
      On Tue, 05 Dec 2006 11:53:21 +0100, Nico <noemail@noemai l.comwrote:
      >
      Dear all,

      I created the following php form.

      <FORM METHOD="POST" ACTION="prova.p hp">
      <b>Combinatio n</b><br><br>
      Element 1: <INPUT NAME="el1" TYPE="TEXT">
      <BR>
      Element 2: <INPUT NAME="el2" TYPE="TEXT">
      <br>
      <INPUT TYPE="SUBMIT" VALUE"Submit">
      </FORM>
      <br>
      Combination<br> <br>

      <?php
      $combination[] = ($_REQUEST["el1"].$_REQUEST["el2"]);
      print_r($combin ation);
      $combinations[] = $combination;
      print_r($combin ations);
      ?>

      When I fill the two text fields of the form in the browser, the inserted
      text is included in the array $combination and then $combination is
      included in the array $combinations.
      When I reload the page, I fill again the two text fields and the new
      inserted text overwrites the old inserted text. This is a problem.
      I'd like that the array "combinatio ns" includes both the old inserted
      text and the new inserted text, but I don't know how to do this.
      Can you help me please?
      Many thanks.
      >
      Hi Nico
      >
      Sounds like you are trying ot make the data persist between page
      refreshes. The best way to handle this is to use 'sessions' and make
      $combinations into a session variable like $_SESSION['combinations'][]
      Just start your PHP code with session_start() ; and then manipulate
      your array :o)
      >
      Chris R.
      Many thanks. I'll try to use sessions.
      Nico

      Comment

      Working...