Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,491 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,716 people online right now. Registration is fast and FREE... Join Now!




Request variables from populated form.

 
Reply to this topicStart new topic

Request variables from populated form.

vicious
27 Jan, 2008 - 06:18 PM
Post #1

New D.I.C Head
*

Joined: 4 Dec, 2007
Posts: 2


My Contributions
So I am trying to request variables on an order confirmation page that were populated from a text file on the form page. The problem I'm having is getting them to show up on the confirmation page.


Here is the web pages for reference.
orderGroceries.php


Here is the text file where the table data is populated.
groceryInventory.txt
CODE

Cabbage    .39    lb
Broccoli    1.89    lb    
Kiwi    0.25    ea
Tomacco    15.86    lb
Free-Range Eggs    3.95    doz




This is the order form.
orderGroceries.php
CODE
<?php
        // Read in the entire file.
        $groceryInventory= file("inventory/groceryInventory.txt");
        // Count the number of elements
        $amount_of_inventory = count($groceryInventory);
        if ($amount_of_inventory == 0)  {
        echo '<p><strong>You have no inventory!  Add some to your stock.</strong></p>';
        }
        echo '<table border="0">
            <tr align="left">
            <th>Item</th>
            <th>Price</th>
            <th>Unit</th>
            <th>Quantity</th>
            <tr>';
                      
        for ($i=0; $i<$amount_of_inventory; $i++)  {
            
            // Alternates Colours
            $colour1 = '#CCCCCC';
            $colour2 = "#FFFFFF";
            $lineCount  = "0";            
            $lineColour = ($i % 2 == 0) ? $colour1 : $colour2;  
            
            // Split up each line
            $line = explode( "\t", $groceryInventory[$i] );
            $line[1] = floatval( $line[1] );
            // $line[2] =intval( $line[2] );
            // $line[3] =intval( $line[3] );
        
            // Output the elements of the text file    
            echo "<tr>
                <td bgcolor='$lineColour'>$line[0]</td>
                <td bgcolor='$lineColour'align='right'> $line[1]</td>
                <td bgcolor='$lineColour' align='right'>$line[2]</td>";
            // Convert string to lower case
            $line[0] = strtolower($line[0]);
            // Remove spaces from string
            $line[0] = str_replace (" ", "", $line[0]);
            //This creates a text input box using the name of the item so it can be passed to the confirmation page
            echo "<td bgcolor='$lineColour' align='right'><input type='text' name='$line[0]' maxlength='2' size='4' /></td>      [color=#FF0000]<== this uses the item name from the text file to name the text input boxes[/color]
            </tr>";
        }
        echo '</table>';
        ?>



This is the file where I am having problems. I want to request the variable names from the previous page without listing them all off ($tomacco = $_POST['tomacco']' etc....). This is an exact copy o the order form, except the input box is replaced by the number of items ordered.

Area in question is at the bottom.
fillOrder.php
CODE

<?php
        
        $firstName = $_POST['firstName'];
        $lastName = $_POST['lastName'];
        $address = $_POST['address'];
        $city = $_POST['city'];

        
        echo '<tr>
                  <td>Full Name: <b>'.$firstName.' '.$lastName.'</b></td>
            </tr>
            <tr>
                  <td>Address: <b>'.$address.'</b></td>
            </tr>
            <tr>    
              <td>City: <b>'.$city.'</b></td>
            </tr>
            <tr>
                <td>';
                // Read in the entire file.
                $groceryInventory= file("inventory/groceryInventory.txt");
                // Count the number of elements
                $amount_of_inventory = count($groceryInventory);
                if ($amount_of_inventory == 0)  {
                echo '<p><strong>You have no inventory!  Add some to your stock.</strong></p>';
                }
                echo '<table border="0">
                    <tr align="left">
                    <th>Item</th>
                    <th>Price</th>
                    <th>Unit</th>
                    <th>Quantity</th>
                    <tr>';
                              
                for ($i=0; $i<$amount_of_inventory; $i++)  {
                    
                    // Alternates Colours
                    $colour1 = '#CCCCCC';
                    $colour2 = "#FFFFFF";
                    $lineCount  = "0";            
                    $lineColour = ($i % 2 == 0) ? $colour1 : $colour2;  
                    
                    // Split up each line
                    $line = explode( "\t", $groceryInventory[$i] );
                    $line[1] = floatval( $line[1] );
                    // $line[2] =intval( $line[2] );
                    // $line[3] =intval( $line[3] );
                
                    // Output the elements of the text file    
                    echo "<tr>
                        <td bgcolor='$lineColour'>$line[0]</td>
                        <td bgcolor='$lineColour'align='right'> $line[1]</td>
                        <td bgcolor='$lineColour' align='right'>$line[2]</td>";
                    // Convert string to lower case
                    $line[0] = strtolower($line[0]);
                    // Remove spaces from string
                    $line[0] = str_replace (" ", "", $line[0]);
                    //This creates a text input box using the name of the item so it can be passed to the confirmation page
                    echo "<td bgcolor='$lineColour' align='right'>



                                          This is where I need the number of items ordered to be     displayed


                                 </td>
                </td>
            </tr>";
        }        
        echo '</table>';
        ?>


I have tried a few things, but cant seem to figure out how to accomplish this task. Any input on how to accomplish this would be greatly appreciated!

This post has been edited by vicious: 27 Jan, 2008 - 06:28 PM
User is offlineProfile CardPM
+Quote Post

MRJ
RE: Request Variables From Populated Form.
28 Jan, 2008 - 02:08 PM
Post #2

D.I.C Head
Group Icon

Joined: 13 Oct, 2007
Posts: 83



Thanked: 1 times
My Contributions
You just need to use the same convention you did when naming the input boxes.

CODE

//This creates a text input box using the name of the item so it can be passed to the confirmation page
//Get the value
                   $OrderValue= $_POST[$line[0]];

                    echo "<td bgcolor='$lineColour' align='right'>$OrderValue</td>
                </td>
            </tr>";


I'm pretty sure that will do the trick
User is offlineProfile CardPM
+Quote Post

vicious
RE: Request Variables From Populated Form.
28 Jan, 2008 - 06:03 PM
Post #3

New D.I.C Head
*

Joined: 4 Dec, 2007
Posts: 2


My Contributions
Wow... Thanks alot MRJ. Dont I feel silly. I think I had defined it at the top of the page at one point, which after testing the method you posted, proved to be out of the scope. Much appreciated.

This post has been edited by vicious: 28 Jan, 2008 - 06:11 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:42PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month