Silly submit?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Salve Håkedal

    Silly submit?

    Maybee my believe in php is a little too big..
    When submitting a small string multiple times
    with this form, I'd expect $file to build up.
    Why does $file contain only the last submit?
    <html>
    <head>
    <title>Silly idea?</title>
    </head>
    <?
    $file .= $_POST['field'];
    echo "
    <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
    <input type=\"text\" name=\"field\">
    <input type=\"submit\" value=\"Submit\ ">
    ";
    echo $file;
    ?>
    </body>
    </html>
  • Jan Pieter Kunst

    #2
    Re: Silly submit?

    In article <DMBec.24735$zf 6.83159@news4.e .nsc.no>,
    Salve Hakedal <ikkje.spam.sal ve@fiolinmaker. no> wrote:
    [color=blue]
    > Maybee my believe in php is a little too big..
    > When submitting a small string multiple times
    > with this form, I'd expect $file to build up.
    > Why does $file contain only the last submit?
    > <html>
    > <head>
    > <title>Silly idea?</title>
    > </head>
    > <?
    > $file .= $_POST['field'];
    > echo "
    > <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
    > <input type=\"text\" name=\"field\">
    > <input type=\"submit\" value=\"Submit\ ">
    > ";
    > echo $file;
    > ?>
    > </body>
    > </html>[/color]

    Because the value of $file isn't saved between submits. Every submit
    does the same thing: concatenate $_POST['field'] to an uninitialized
    variable $file which defaults to the empty string.

    JP

    --
    Sorry, <devnull@cauce. org> is een "spam trap".
    E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

    Comment

    • Garp

      #3
      Re: Silly submit?


      "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> wrote in message
      news:DMBec.2473 5$zf6.83159@new s4.e.nsc.no...[color=blue]
      > Maybee my believe in php is a little too big..
      > When submitting a small string multiple times
      > with this form, I'd expect $file to build up.
      > Why does $file contain only the last submit?[/color]
      <snip>

      You echo the contents into the form, but not as a form variable.

      <input type=\"text\" name=\"field\">
      You haven't loaded this field with the previous contents (no 'value'
      attribute), so it's empty each time.

      Garp


      Comment

      • Pedro Graca

        #4
        Re: Silly submit?

        Salve Håkedal wrote:[color=blue]
        > Maybee my believe in php is a little too big..
        > When submitting a small string multiple times
        > with this form, I'd expect $file to build up.
        > Why does $file contain only the last submit?
        ><html>
        ><head>
        ><title>Silly idea?</title>
        ></head>
        ><?[/color]

        error_reporting (E_ALL);
        ini_set('displa y_errors', '1');
        [color=blue]
        > $file .= $_POST['field'];[/color]

        // The previous statement will generate a Notice about $file not having
        // been previously defined
        [color=blue]
        > echo "
        ><form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
        ><input type=\"text\" name=\"field\">
        ><input type=\"submit\" value=\"Submit\ ">
        > ";
        > echo $file;
        > ?>
        ></body>
        ></html>[/color]

        Try this instead:

        <html>
        <head>
        <title>Good Idea!</title>
        </head>
        <body>
        <?php
        error_reporting (E_ALL);
        ini_set('displa y_errors', '1');

        session_start() ;
        if (!isset($_SESSI ON['file'])) $_SESSION['file'] = '';

        $_SESSION['file'] .= $_POST['field'] . '<br/>';

        echo "
        <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
        <input type=\"text\" name=\"field\">
        <input type=\"submit\" value=\"Submit\ ">
        ";

        echo $_SESSION['file'];
        ?>
        </body>
        </html>

        --
        USENET would be a better place if everybody read: : mail address :
        http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
        http://www.netmeister. org/news/learn2quote2.ht ml : "text/plain" :
        http://www.expita.com/nomime.html : to 10K bytes :

        Comment

        • Salve Håkedal

          #5
          Re: Silly submit?

          Garp skreiv:
          [color=blue]
          >
          > "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> wrote in message
          > news:DMBec.2473 5$zf6.83159@new s4.e.nsc.no...[color=green]
          >> Maybee my believe in php is a little too big..
          >> When submitting a small string multiple times
          >> with this form, I'd expect $file to build up.
          >> Why does $file contain only the last submit?[/color]
          > <snip>
          >
          > You echo the contents into the form, but not as a form variable.
          >
          > <input type=\"text\" name=\"field\">
          > You haven't loaded this field with the previous contents (no 'value'
          > attribute), so it's empty each time.[/color]
          But when I try this I submit a new string each time..
          Only the last submitted string is printed..

          Salve

          Comment

          • Salve Håkedal

            #6
            Re: Silly submit?

            Jan Pieter Kunst skreiv:
            [color=blue]
            > In article <DMBec.24735$zf 6.83159@news4.e .nsc.no>,
            > Salve Hakedal <ikkje.spam.sal ve@fiolinmaker. no> wrote:
            >[color=green]
            >> Maybee my believe in php is a little too big..
            >> When submitting a small string multiple times
            >> with this form, I'd expect $file to build up.
            >> Why does $file contain only the last submit?
            >> <html>
            >> <head>
            >> <title>Silly idea?</title>
            >> </head>
            >> <?
            >> $file .= $_POST['field'];
            >> echo "
            >> <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
            >> <input type=\"text\" name=\"field\">
            >> <input type=\"submit\" value=\"Submit\ ">
            >> ";
            >> echo $file;
            >> ?>
            >> </body>
            >> </html>[/color]
            >
            > Because the value of $file isn't saved between submits. Every submit
            > does the same thing: concatenate $_POST['field'] to an uninitialized
            > variable $file which defaults to the empty string.
            >
            > JP
            >[/color]
            I thought value of $file was (saved and) buildt up by using .=

            Comment

            • Garp

              #7
              Re: Silly submit?


              "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> wrote in message
              news:%qCec.6192 $px6.87085@news 2.e.nsc.no...[color=blue]
              > Garp skreiv:
              >[color=green]
              > >
              > > "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> wrote in message
              > > news:DMBec.2473 5$zf6.83159@new s4.e.nsc.no...[color=darkred]
              > >> Maybee my believe in php is a little too big..
              > >> When submitting a small string multiple times
              > >> with this form, I'd expect $file to build up.
              > >> Why does $file contain only the last submit?[/color]
              > > <snip>
              > >
              > > You echo the contents into the form, but not as a form variable.
              > >
              > > <input type=\"text\" name=\"field\">
              > > You haven't loaded this field with the previous contents (no 'value'
              > > attribute), so it's empty each time.[/color]
              > But when I try this I submit a new string each time..
              > Only the last submitted string is printed..
              >
              > Salve
              >[/color]

              Looks like I missed something I thought obvious, you're right. Try this.

              <html>
              <head>
              <title>Silly idea?</title>
              </head>
              <?
              $file = $_POST['text'].$_POST['field'];
              echo "
              <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
              <input type=\"text\" name=\"field\">
              <input type=\"hidden\" name=\"text\" value=\"$file\" >
              <input type=\"submit\" value=\"Submit\ ">";
              echo $file;
              ?>

              HTH
              Garp


              Comment

              • Salve Håkedal

                #8
                Re: Silly submit?

                [color=blue]
                > Looks like I missed something I thought obvious, you're right. Try this.
                >
                > <html>
                > <head>
                > <title>Silly idea?</title>
                > </head>
                > <?
                > $file = $_POST['text'].$_POST['field'];
                > echo "
                > <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
                > <input type=\"text\" name=\"field\">
                > <input type=\"hidden\" name=\"text\" value=\"$file\" >
                > <input type=\"submit\" value=\"Submit\ ">";
                > echo $file;
                > ?>
                >
                > HTH
                > Garp[/color]

                *****THANK YOU, THAT'S IT!*******

                Salve

                Comment

                • Garp

                  #9
                  Re: Silly submit?


                  "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> wrote in message
                  news:KVCec.2474 7$zf6.83403@new s4.e.nsc.no...[color=blue]
                  >[color=green]
                  > > Looks like I missed something I thought obvious, you're right. Try this.
                  > >
                  > > <html>
                  > > <head>
                  > > <title>Silly idea?</title>
                  > > </head>
                  > > <?
                  > > $file = $_POST['text'].$_POST['field'];
                  > > echo "
                  > > <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
                  > > <input type=\"text\" name=\"field\">
                  > > <input type=\"hidden\" name=\"text\" value=\"$file\" >
                  > > <input type=\"submit\" value=\"Submit\ ">";
                  > > echo $file;
                  > > ?>
                  > >
                  > > HTH
                  > > Garp[/color]
                  >
                  > *****THANK YOU, THAT'S IT!*******
                  >
                  > Salve[/color]

                  Well, it works, but it's not scalable. If it gets any more complicated,
                  database it.

                  Glad to help though.

                  Garp


                  Comment

                  • Salve Håkedal

                    #10
                    Re: Silly submit?

                    Garp skreiv:
                    [color=blue]
                    >
                    > "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> wrote in message
                    > news:KVCec.2474 7$zf6.83403@new s4.e.nsc.no...[color=green]
                    >>[color=darkred]
                    >> > Looks like I missed something I thought obvious, you're right. Try
                    >> > this.
                    >> >
                    >> > <html>
                    >> > <head>
                    >> > <title>Silly idea?</title>
                    >> > </head>
                    >> > <?
                    >> > $file = $_POST['text'].$_POST['field'];
                    >> > echo "
                    >> > <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
                    >> > <input type=\"text\" name=\"field\">
                    >> > <input type=\"hidden\" name=\"text\" value=\"$file\" >
                    >> > <input type=\"submit\" value=\"Submit\ ">";
                    >> > echo $file;
                    >> > ?>
                    >> >
                    >> > HTH
                    >> > Garp[/color]
                    >>
                    >> *****THANK YOU, THAT'S IT!*******
                    >>
                    >> Salve[/color]
                    >
                    > Well, it works, but it's not scalable. If it gets any more complicated,
                    > database it.
                    >
                    > Glad to help though.
                    >
                    > Garp[/color]
                    I intend to make a sql-string from it..
                    Salve

                    Comment

                    Working...