Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Submitting data from multiple forms

    What I'm trying to do is display all the appropriate records, the user will be able to use a checkbox to select the data records he wants submitted and then select the submit button.

    So far it's been nothing but headache though. Am I approaching this issue in the right way?

    The big problem I'm having is that there is no simple way to group the results from different forms. I was hoping the <fieldset> tag would solve my problem but it hasn't.

    The approach I've taken is to send all the data via arrays and use a while function to pick the "select" array elements but so far it's not been working out.

    Here is the code below.

    PHP Code:
    <?php

    /**
     * @author Julian Josephs
     * @copyright 2009
     */

    $mysql = new mysqli('localhost''root''password''hoteldb') or die($mysql->error);

    ?>

    <html>
    <head></head>

    <body>

    <h2>Select the Guests that are Checking in</h2>

    <?php

        $guestObj 
    $mysql->query("SELECT * FROM admissiondata") or die ($mysql->error);
        
        echo 
    '<form method="POST" action="">';
        
        
    $count 0;
        
            while( 
    $guestRecord $guestObj->fetch_object() )
            {
                echo 
    '<fieldset>';
                echo 
    '<legend>' $guestRecord->lastName '</legend>';
                
                echo 
    '<input type="text" readonly="readonly" name="Reservation Number[]" value="' $guestRecord->reservationNum '" size="4" />';
                echo 
    '<input type="text" readonly="readonly" name="Guest Number[]" value="' $guestRecord->guestNum '" size="4" />';
                echo 
    '<input type="text" readonly="readonly" name="First Name[]" value="' $guestRecord->firstName '" size="10" />';
                echo 
    '<input type="text" readonly="readonly" name="Middle Initial[]" value="' $guestRecord->mI '" size="1" />';
                echo 
    '<input type="text" readonly="readonly" name="Last Name[]" value="' $guestRecord->lastName '" size="10" />';
                echo 
    '<input type="text" readonly="readonly" name="Credit Card[]" value="' $guestRecord->creditCard '" size="14" />';
                echo 
    '<input type="text" readonly="readonly" name="Cell Number[]" value="' $guestRecord->cellNumber '" size="7" />';
                echo 
    '<input type="text" readonly="readonly" name="Home Number[]" value="' $guestRecord->homeNumber '" size="7" />';
                echo 
    '<input type="text" readonly="readonly" name="Work Number[]" value="' $guestRecord->workNumber '" size="7" />';
                echo 
    '<input type="text" readonly="readonly" name="Num Of Days[]" value="' $guestRecord->numOfDays '" size="1" />';
                echo 
    '<input type="text" readonly="readonly" name="Charge[]" value="' $guestRecord->charge '" size="6" />';
                echo 
    '<input type="text" readonly="readonly" name="Cancelled[]" value="' $guestRecord->canceled '" size="6" />';
                echo 
    '<input type="text" readonly="readonly" name="Guest Room Num[]" value="' $guestRecord->guestRoomNum '" size="1"/>';
                echo 
    '<input type="checkbox" name="select[]" value="'$count '" />';
                
                echo 
    '</fieldset>';
                
                echo 
    '<br />';
                    
                
    $count++;        
            }
        
        echo 
    '<input type="submit" name="Add Records" value="Add Records" />';
        echo 
    '</form>';
            
    ?>

    <?php

        
    if(isset($_POST['Add_Records']))
        {
            echo 
    '<pre>';
            
    print_r($_POST);
            echo 
    '</pre>';
            
            
    $ReservationNumber = array( $_POST['Reservation_Number'] );
            
    $select = array( $_POST['select'] );
            
            
            
    // PROBLEM HERE
            
            
    $recNum 0;
            
            while( 
    $recNum 50 )
            {
                
    $seeker 0;            
                while( 
    $seeker 50  )
                {
                    if( 
    $select[0][$recNum] == $seeker )
                    {
                        echo 
    $ReservationNumber[0][$recNum];
                        echo 
    '<br />';
                        echo 
    $select[0][$recNum];
                        echo 
    '<br />';
                    }
                    
    $seeker++;
                }
                
    $recNum++;
            }
            
            
    //echo '123<pre>';
            //print_r($selected);
            //echo '</pre>098';
        
    }
    ?>
    </body>

    </html>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    How about appending the $count along with the name attributes of inputs, like
    PHP Code:
    echo '<input type="text" readonly="readonly" name="Reservation_Number_'.$count.'[]" value="' $guestRecord->reservationNum '" size="4" />';
    echo 
    '<input type="text" readonly="readonly" name="Guest_Number_'.$count.'[]" value="' $guestRecord->guestNum '" size="4" />'
    btw, I think a bank space in the name attribute is invalid. Validate your generated html code before moving to other areas.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I tried your method but things were getting too complicated. I just made each record a form an gave each form a ''Add Record'' submit button.

    I cut and pasted my html code to the validator but all I got were invalid docutype errors. Nothing like what you mentioned.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •