PHP $_POST with invalid data?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gamernaveen
    New Member
    • Oct 2007
    • 28

    PHP $_POST with invalid data?

    I've been busy coding a signup system with PHP.
    There are 2 forms , form1 and form2.

    form1 contains:
    Name , Age ,
    form 2 contains
    Username , Password , Repeat Pass , Email

    I use POST method to submit the form.
    Here , name and age is sent from form1 to form2 and form2 gets it through $_POST vars. The next step is submitform.php , once form2 gets form1 data with $_POST , it submits its data (Username,Pass. .) with form1 data as a
    <input type="hidden"> field.
    Ex.
    Form2 :[php]
    <form method="POST" action="submitf orm.php">
    <input type="text" name="username"/>
    <input type="password" name="password"/>
    <input type="pass2" name="repeatpas s"/>
    <input type="email" name="email"/>
    <input type="hidden" name="name" value="<? echo $_POST['name'];?>"/>
    <input type="hidden" name="age" value="<? echo $_POST['age'];?>"/>
    <input type="submit" name="sub" value="submit">
    </form>[/php]Everything works fine but the prob am facing is , invalid data.
    Everything that was submitted gets sent correctly.
    But many times , I get name=ssss and age=32 in the submitform.php even though I had my name as "gamer" and age as "20" , once I go back and resubmit , it comes fine but again at times , I get the data "ssss" and "32" even when it wasnt submitted. I use Opera 9.26.
    Why does this happen ? How do I avoid it?

    Please help me.
    Thanks.
    Last edited by ronverdonk; Mar 20 '08, 05:15 PM. Reason: code tags
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • gamernaveen
      New Member
      • Oct 2007
      • 28

      #3
      Originally posted by ronverdonk
      Please enclose your posted code in [code] tags (See How to Ask a Question).

      This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

      Please use [code] tags in future.

      MODERATOR
      Oh am really sorry , wont do that in future. LoL

      Anyway guys please help.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Only way to establish that is to also show the code of form1 and form2 scripts. That is the only way to be able to follow the data (POST) stream.

        And don't forget the code tags!

        Ronald

        Comment

        • gamernaveen
          New Member
          • Oct 2007
          • 28

          #5
          Originally posted by ronverdonk
          Only way to establish that is to also show the code of form1 and form2 scripts. That is the only way to be able to follow the data (POST) stream.

          And don't forget the code tags!

          Ronald
          okay here is the flow

          form 1
          [PHP]
          <form method="POST" action="form2.p hp">
          <input type="text" name="name"/>
          <input type="age" name="age"/>
          <input type="submit" name="subone" value="submit"/>
          </form>
          [/PHP]
          This submits to form 2:
          form2
          [PHP]
          <form method="POST" action="submitf orm.php">
          <input type="text" name="username"/>
          <input type="password" name="password"/>
          <input type="pass2" name="repeatpas s"/>
          <input type="email" name="email"/>
          <input type="hidden" name="name" value="<? echo $_POST['name'];?>"/>
          <input type="hidden" name="age" value="<? echo $_POST['age'];?>"/>
          <input type="submit" name="sub" value="submit">
          </form>
          [/PHP]
          This submits to submitform.php
          submitform.php
          [PHP]
          <?
          $user=$_POST['username'];
          $pass=$_POST['password'];
          $rpass=$_POST['repeatpass'];
          $email=$_POST['email'];
          $name=$_POST['name'];
          $age=$_POST['age'];

          $echo "Username:$user <br/>Password:$pass <br/>Repeat:$rpass< br/>
          Email:$email<br/>Name:$name<b r/>Age:$age<br/>";
          ?>
          [/PHP]

          Now as you see everything gets submitted to and displays the results but the prob is at times I get "Name=ssss Age=32" even when the name and age werent ssss and 32. I dont know why this happens , I use Opera , please help me.

          Its just the invalid data thats get posted.

          Comment

          • dlite922
            Recognized Expert Top Contributor
            • Dec 2007
            • 1586

            #6
            Originally posted by gamernaveen
            okay here is the flow

            form 1
            [PHP]
            <form method="POST" action="form2.p hp">
            <input type="text" name="name"/>
            <input type="age" name="age"/>
            <input type="submit" name="subone" value="submit"/>
            </form>
            [/PHP]
            This submits to form 2:
            form2
            [PHP]
            <form method="POST" action="submitf orm.php">
            <input type="text" name="username"/>
            <input type="password" name="password"/>
            <input type="pass2" name="repeatpas s"/>
            <input type="email" name="email"/>
            <input type="hidden" name="name" value="<? echo $_POST['name'];?>"/>
            <input type="hidden" name="age" value="<? echo $_POST['age'];?>"/>
            <input type="submit" name="sub" value="submit">
            </form>
            [/PHP]
            This submits to submitform.php
            submitform.php
            [PHP]
            <?
            $user=$_POST['username'];
            $pass=$_POST['password'];
            $rpass=$_POST['repeatpass'];
            $email=$_POST['email'];
            $name=$_POST['name'];
            $age=$_POST['age'];

            $echo "Username:$user <br/>Password:$pass <br/>Repeat:$rpass< br/>
            Email:$email<br/>Name:$name<b r/>Age:$age<br/>";
            ?>
            [/PHP]

            Now as you see everything gets submitted to and displays the results but the prob is at times I get "Name=ssss Age=32" even when the name and age werent ssss and 32. I dont know why this happens , I use Opera , please help me.

            Its just the invalid data thats get posted.
            that is weird, but you have a little error:

            <input type="age" name="age"/>

            should be

            <input type="text" name="age"/>

            there's no type="age" ^_^

            that might cause the problem.

            Also, follow the trail, where does the values happen, the first submit or second submit?

            View source form2 and look at the values in the hidden field and see what they are.

            With weird problems like this you have to STEP it (ie check the values with a end function like die() which will end the program at the point, printing variable values then will give you better tracing ability that will lead you to pin pointing your problem.

            Good luck and happy coding,

            And first day of spring!! :)

            DM

            Comment

            • gamernaveen
              New Member
              • Oct 2007
              • 28

              #7
              Originally posted by dlite922
              that is weird, but you have a little error:

              <input type="age" name="age"/>

              should be

              <input type="text" name="age"/>

              there's no type="age" ^_^

              that might cause the problem.

              Also, follow the trail, where does the values happen, the first submit or second submit?

              View source form2 and look at the values in the hidden field and see what they are.

              With weird problems like this you have to STEP it (ie check the values with a end function like die() which will end the program at the point, printing variable values then will give you better tracing ability that will lead you to pin pointing your problem.

              Good luck and happy coding,

              And first day of spring!! :)

              DM
              LoL sorry for the invalid type error , didnt check it though.
              Anyway I fixed the bug looking at the chain.
              Thanks.

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by gamernaveen
                LoL sorry for the invalid type error , didnt check it though.
                Anyway I fixed the bug looking at the chain.
                Thanks.
                And the bug was?

                Regards

                Comment

                Working...