I have a multiple page survey.

Page1.html calls getpage1.php through the action attribute of the form tag.

getpage1.php does three things:
first it generates a timestamp which becomes variable called $datein;
next it writes all data to a database;
last, an include statement calls the second page of the survey.

I want to pass the variable $datain from page to page of the survey.

<input type="hidden" name="datein" value=" <php echo '$datein'; ?> />

The problem I'm having is that instead of getting the value of $datein appearing in the source code of the second page, I get the variable name instead.

Any ideas or help welcomed.

    Hi Pthes

    You don't pass variables this way. PHP is dreadfully clever: if you put a value into a hidden field, or any form field in fact, you can pick it up on the target page (getpage1.php in your case) as a variable - magic! I couldn't believe it was that simple when I first started learning PHP.

    So here's what you want in your form:

    <!-- line in form -->
    <input type="hidden" name="datein" value="mydate">

    In the pick-up page you have this:

    #grab my $datein var
    $new_datein = $_GET['$datein'];

    Adjust as necessary (POST / GET; register_globals on or off)

    HTH

    Norm

      Thanks Norm, I'm aware of what you've written. However, that works fine if the variable value is created in the first form.

      The problem here is that the value of the timestamp is created in the PHP script. I then want to pass that value to the form.

      It's sort of backwards from what the examples always show.

        Do you not want to just pass it in the include statement w/ a ?$date_in??? If not this has worked for me

         <input type="hidden" name="date_in" value="<?php print $date_in?>">
        

        Fairly similar but I know it works on my page.

        Hope this helps

        r2

          Hey Norman:

          I'm having a similar problem, and want to take the results of checkbox input (with 2 related fields) from page 1 and have them display on page 2 as a "Preview Page" before final inserting into a DB.

          Using reg globals off, do you know what 'action' statement I need to use on page1 to automatically go to page1 when the 'submit' button is clicked on page1?

          I'm wondering if some kind of session has to be used if a person wants to back up from page2 (for any corrections to the page1 selections), and NOT have the page1 form reset and have to start over from scratch? I mostly see "expiry" warnings & a request to 'reset' when trying to back up.

          My hidden fields have to be in an array. Like: myfield[]Another chap has been trying to help me but it just ain't working.

          Thanks much.

            Hi PHP-Learner

            You don't need any special action. You set the form action on page 1 to page2.php and the method to either POST or GET and then on page 2 you pick up the variables thus:

            $checkbox = $_GET['$mycheckbox'];

            Does that answer your question?

            Norm

              The problem is because you're using single-quotes in echo '$datein'. PHP doesn't do variable interpolation within single quotes, so if you as to echo '$datein', $datein is what you get, as you've discovered.

              If you want variable interpolation you typically want double quotes, but in this case you don't need quotes at all.

              echo $datein
              

              will echo a string representation of $datein quite happily. You never need to go

              echo "$datein"
              

              which is in fact a big waste of time.

                Originally posted by Norman Graham
                Hi PHP-Learner

                You don't need any special action. You set the form action on page 1 to page2.php and the method to either POST or GET and then on page 2 you pick up the variables thus:

                $checkbox = $_GET['$mycheckbox'];

                Does that answer your question?

                Norm [/B]

                Hi Norman:

                Tnx for the info, but I'm still lost about the 2 related hidden fields with the checkbox.

                If I understand things correctly, the form statement would be like:

                <form name="form1" method="POST" action="<?php echo page2.php; ?>"
                

                But part of the problem is that I can't even get the following (one of many suggested codings) to display correctly on Page 1:

                <TD width="30" align="center"> 
                <input name="taxoption[]" type="checkbox" value="1"> 
                <input type="hidden" name="mtax[]" value="<?php echo $row['taxrate']?>"> 
                <input type="hidden" name="mcity[]" value="<?php echo $row['cityname']?>"> 
                </TD> 
                

                In other words, if there are 500 checkbox options displaying blank (cullled from a MySQL Table), and only 3 get checked, then it is ONLY the 3 checked ones I want to display on Page2 which will also have code to ultimately Insert these into a separate MySQL table.

                I've had several others trying to help me with this but nothing seems to be working.

                Thank you for any new additional insights.

                  Hi PHP-Learner

                  I think there seems to be a bit of a misunderstanding here, probably on my part. You're citing various lines of code, but it's not clear where they come from. Which page contains your HTML form, where is it going to and what do want to do with it? Is your set-up like this?:

                  Page 1: HTML form with txt input, checkboxes, radio buttons and the like

                  Page 2: A processing page in which the user input is checked, validated and some message is sent to the browser.

                  In the action parameter of the form, you just put the action as page2.php - you don't need to echo anything, i.e.

                  <form name="form1" method="POST" action="page2.php">

                  This is pure HTML and doesn't require any fancy footwork.

                  In page 1, you've got a bunch of hidden form fields which extract their values from a MySQL table, e.g. taxrate and cityname. I assume you have created the array $row[] somewhere at the top of page 1 before the HTML form even starts. This shouldn't be necessary. If these values are already fixed in the MySQL table, you can just pick them up directly in page2.php - you don't need to send them as hidden form fields from page 1 to page 2.

                  I suggest you post page 1 and page 2. If they are very long, you might want to attach them as a zip file. It's perfectly possible that I'm just being stupid, but I can't understand what is coming from where and where it's going to. If I'm just being thick, then ignore me and wait for some of the clever people to help you out.

                  Btw - if you really do have 500 checkboxes, I suggest splitting them into several forms because no-one is going to read and click through them all unless there is a cash prize for everyone who does so.

                  Sorry not to be more quick-witted

                  Norm

                    Originally posted by Norman Graham
                    Sorry not to be more quick-witted
                    Norm

                    Hey Norman:

                    You are VERY 'quick-witted' 😃

                    I should have explained...this is not for web users...it is a 'one-time' Master Configuration process, if you will, for Admin type use only.

                    OK...I .zipped up 2 files and tried to provide more specific info (as // comments) and stuck it up at:

                    The filename says it all as to where I am right now. I can't find a 'Smilie' for 'OVERWHELMED', so I will pick the closest one I can think of.

                    😕 😕 😕

                    Thanks for your assistance in helping me work through this, umh, "Nightmare".

                    Oh...there are a couple of lines of code in there for testing purposes to see what is going on with the array(s)...these are not a part of the final page(s).

                    My latest thought is that instead of trying to use 2 'hidden' fields, maybe only one with the $row['ID'] from Page 1 displayed checkboxes "CHECKED" to determine which will then show on Page 2 ???

                    Ooops... RE: (zip file comments):
                    "Whichever checkboxes/Cities are selected (1 or all)"...
                    should read "... (1, 3, 7, all, etc., etc.)

                    Tnx.

                      Still unresolved. This thing is a Nightmare!

                        from phpleaner code

                        <form name="form1" method="post">
                        <select name="taxname" id="select1">
                        <option value="" style="color:ff0000" selected>- Select One Option - 
                        </option>
                        <?php 
                        while ($row = mysql_fetch_assoc($list)) {
                        ?>
                        <option value="<?php echo $row['taxname']?>"></option><br>
                        <?php
                        }
                        ?>
                        </select>
                        </form>
                        

                        as from what i saw from your form there is a name and method but what about the action where do u want the action go is it with the same file or on the other file. well that's just maybe the reason u cant figure out whats wrong

                          if i dont answer the question maybe post what do u really want to do and what it should be in more detailed explaination and im willing to help you on this

                            Hi PHP Learner

                            Sorry - I've been otherwise occupied and not visiting the board. Listen, I'd have to look at this in peace for a few minutes - possibly later today unless Osusano gets there before me, which would be fine.

                            First thing I'd check, though, is what version of PHP you are using. The constants for picking up globals are:

                            $SERVER
                            $
                            GET
                            $_POST

                            The versions you are using are depreciated, although they will still work with older releases. I'd check this out with the manual.

                            I'll try and check back later today, but I can't promise - I have to create 30 English grammar exercises by sundown ...

                            Talk to you later

                            Norm 😃

                              osusano and Norman:

                              Tnx for the replies.

                              All of the information is in // comments WITHIN the .php (.zip) file.

                              My ISP runs PHP 4.3.xxx with "Register_globals OFF" (I can not change this).

                              Thanks again!!!

                                Originally posted by osusano
                                from phpleaner code
                                as from what i saw from your form there is a name and method but what about the action where do u want the action go is it with the same file or on the other file. well that's just maybe the reason u cant figure out whats wrong

                                Ooops...forgot to comment on this.

                                For testing right now, it is just to display the 'cityname'. But I will need to have the associated 'taxrate' available to pass to another script. This may be 'hidden' field as well?

                                  Originally posted by osusano
                                  from phpleaner code

                                  <form name="form1" method="post">
                                  <select name="taxname" id="select1">
                                  <option value="" style="color:ff0000" selected>- Select One Option - 
                                  </option>
                                  <?php 
                                  while ($row = mysql_fetch_assoc($list)) {
                                  ?>
                                  <option value="<?php echo $row['taxname']?>"></option><br>
                                  <?php
                                  }
                                  ?>
                                  </select>
                                  </form>
                                  

                                  [/B]

                                  Thanks, but this still does NOT display a record choice from the DB.

                                  There is only a blank line where something should display. I checked the DB...and I do have one valid entry in the table!!!

                                  Strange.

                                    A "Revelation" ...

                                    I was just looking at a post on another forum about 'checkboxes'.

                                    It appears a better way for me to go is to add a "checked" column to the initial DB table, which would then NOT require a 2nd table if, when an entry is 'checked', either a '1' (true) or '0' (false) is written back to the Table.

                                    Then, subsequently, I can have different access pages to the data, but still only deal with ONE "Master" Table.

                                    Does this make sense???

                                    If so, then:

                                    -- SQL --
                                    --CITY Table
                                    CREATE TABLE stw_city (
                                    ID int not null auto_increment primary key,
                                    cityname varchar(30) not null,
                                    taxrate FLOAT(7) not null,
                                    checked char(3) null
                                    );

                                    And I could use either 'yes' or 'no' in the 'checked' column/field. Or, maybe an ENUM column/field instead?

                                    Now, exactly how to get it to work?

                                      Hmm...based upon the .zipped code I stuck up and the new 'checkbox' column/field approach, this is how perhaps it should work.

                                      PAGE 1:
                                      Reads from the one table and displays a "Master List" of choices to include a blank checkbox.

                                      When one or more checkboxes are checked and the Submit button is clicked, the appropriate row cityname gets a 'yes' put into the 'checkbox' column/field.

                                      Then, I am transferred to...

                                      PAGE 2:
                                      This displays a condensed/summary list of ONLY those citynames which have been checked 'yes' (from the same one table). If an addition or deletion needs to take place before a "Final Process" (Submit) button is clicked, a 2nd Submit button called "Revise" would take me back to Page 1 ... but to display ANY checked items to date.

                                      PAGE 3:
                                      This is a standalone page with the 'Drop Down' list which ONLY displays 'checked' items from the ONE Table used for everything.
                                      But here is the catch...whichever cityname is selected, I will need to pass both the 'taxrate' FOR THAT 'cityname' selected on to some other script or cart. But I don't know how to configure the 'hidden' tag so this will happen. Would that involve either a $row['ID'] ... or ... the 'cityname' associated with it to work?

                                      The only other thing I can think of would be to have the choices/options display as 'Radio Buttons', but if there are 10 or 15 choices, this could be more messy than a drop down list.

                                      Actually, now that I think about it, 'cityname' will actually be comprised of entries for:

                                      1. City (Name)
                                      2. County (Name)

                                      So the way it is supposed to work is that if a person lives in one of the displayed Cities, they would click that Radio Button and then Submit.

                                      BUT, if they do NOT live in a listed City, BUT live in one of the displayed County (Names), then it is the County name Radio Button which must be chosen. And then...

                                      Finally, if they are NOT in one of the Cities OR Counties, then a final option of: (radio) Base Rate must be chosen.

                                      If I take the Radio Button approach, then I could put specific instructional text right above each 'section' (although it is really all contained within ONE 'form' to be submitted.

                                      Hmm... now I'm thinking it would be a 'cleaner' page to have 2 Drop-Down lists and I can put the same Instructions above each drop down list. Like: Choose one of the following cities. If you do NOT live in one of these cities, proceed to the next section.

                                      Then, in the 'County' (Name) drop-down, instructions like: Choose one of the following counties. If you do NOT live in one of these counties, proceed to the final section.

                                      There, could be one 'Radio Button' option saying: State Base Rate.
                                      OR, if NO City is selected and NO County selected, then the Value for passing on would be a predetermined "State Base Rate".

                                      Umh, perhaps a separate entry in the 'Master Table' of City/County names could be: State Base Rate...and then this could be read from the Table directly into the Page 3 display.

                                      Thanks again for the assistance.

                                        Norman:

                                        BTW, I see you are in Berlin. FYI, I am 50% German heritage on my mother's side 😃

                                        OK...here is an example of my recent post:

                                           [url]http://www.xgenesis.com/citycountystate.html[/url]

                                        But if user makes a mistake and chooses a city, I don't think Radio button options allow for 'unchecking' the radio button.

                                        Hmmm...

                                        Maybe separate pages...one for City, then one for County, then finally, State. But if a City (or County) IS selected from one of those pages, user would need to go directly to checkout page.

                                        Actually, perhaps the County list should be kept in a Separate Table, or else yet another column/field added to the Main Table to identify whether City OR County.

                                        I was also thinking on Master Page that ONE 'text' field would be for entry of the "State Base Rate" which would then get written to the Table along with the checkbox items 'checked'

                                        Decisions, decisions, decisions.🆒

                                          Write a Reply...