SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Angry Results of Form (Array) not Displaying Correctly

    I can't seem to figure out why this is not working properly. The first page is a form with checkboxes and then a textbox for quantity. (www.soupladle.com/order.php). The second box of code here is the results of that form, but in a summary printable format.

    Form:
    PHP Code:
    while( $list mysql_fetch_array$query ) )
    {
        
    $soupCheckboxes .='<tr><td><font face="verdana" size="2" color="#000000"><input type="checkbox" name="SoupName[]" value="' 
                        
    $list["SoupName"]
                        . 
    '">' 
                        
    htmlspecialchars($list["SoupName"]) 
                        . 
    '</td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Cup[]"></td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Bowl[]"></td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Mulloy[]">' 
                        
    '</tr>';
    }
    echo (
    $soupCheckboxes); 
    And the results of that form in a summary format. This is where the textboxes named Cup, Bowl, and Mulloy are not showing up. They are blank even if a value is entered on the form.
    PHP Code:
    $soupName $_POST['SoupName'];
    $cup $_POST['Cup'];
    $bowl $_POST['Bowl'];
    $mulloy $_POST['Mulloy'];
    $count count($soupName);
    //example
    echo '<table border="0" width="40%"><tr><td><font size="2"><b>Soup Name</b></td><td><font size="2"><b>Cups</b></td><td><font size="2"><b>Bowls</b></td><td><font size="2"><b>Mulloy</b></td></tr>';
    for (
    $i 0$i $count$i++)
    {
        echo 
    '<tr>';
        echo 
    '<td><font size=2> ' $soupName[$i] . '</td>';
        echo 
    '<td><font size=2> ' $cup[$i]      . '</td>';
        echo 
    '<td><font size=2> ' $bowl[$i]      . '</td>';
        echo 
    '<td><font size=2> ' $mulloy[$i]     . '</td>'
        echo 
    '</tr>';   

    Any ideas? It doesn't make sense to me why the soupName would be passed through, but not the others. Did I set this up correctly, or am I just totally ignorant?

    The result always returns the names of the soups checked, but not the quantity entered in the textbox. What is wrong here? If I have totally confused you, try it out here: www.soupladle.com/order.php
    TAKE A WALK OUTSIDE YOUR MIND.

  2. #2
    As the name suggests... trickie's Avatar
    Join Date
    Jul 2002
    Location
    Melbourne, Australia
    Posts
    678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need the [] on any of the names of text fields:

    PHP Code:
    name="Cup[]" 

  3. #3
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    So get rid of those brackets on the Form Cup Bowl and Mulloy?

    Why do I need to brackets on the SoupName then?
    TAKE A WALK OUTSIDE YOUR MIND.

  4. #4
    As the name suggests... trickie's Avatar
    Join Date
    Jul 2002
    Location
    Melbourne, Australia
    Posts
    678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You only need the brackets for the input name, if the form element is capable of having multiple values.

    That way you get all the multiple values in an array in PHP.

    see http://www.php.net/manual/en/languag...s.external.php

  5. #5
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I think I understand what your saying, but I still can't get it to function properly. Here is my current form code:

    PHP Code:
    while( $list mysql_fetch_array$query ) )
    {
        
    $soupCheckboxes .='<tr><td><font face="verdana" size="2" color="#000000"><input type="checkbox" name="SoupName[]" value="' 
                        
    $list["SoupName"]
                        . 
    '">' 
                        
    htmlspecialchars($list["SoupName"]) 
                        . 
    '</td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Cup"></td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Bowl"></td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Mulloy">' 
                        
    '</tr>';
    }
    echo (
    $soupCheckboxes); 
    I took the [] out of Cup, Bowl, and Mulloy. Is there something else that I'm missing?
    TAKE A WALK OUTSIDE YOUR MIND.

  6. #6
    As the name suggests... trickie's Avatar
    Join Date
    Jul 2002
    Location
    Melbourne, Australia
    Posts
    678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you can have multiple form elements with the same name except for the ones that use [], such as select or radio buttons etc

    You need to have a unique name for each text input element

  7. #7
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    But I don't know how many text inputs there will be as the list is created daily depending on which soups are offered that day. The entire point of this is to create a dynamic list.
    TAKE A WALK OUTSIDE YOUR MIND.

  8. #8
    As the name suggests... trickie's Avatar
    Join Date
    Jul 2002
    Location
    Melbourne, Australia
    Posts
    678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    while( $list mysql_fetch_array$query ) )
    {
            
    $soupCheckboxes .='<tr><td><font face="verdana" size="2" color="#000000"><input type="checkbox" name="'.$list["SoupName"].'[]" value="' 
           
    $list["SoupName"]
           . 
    '">' 
           
    htmlspecialchars($list["SoupName"]) 
           . 
    '</td>'
           
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="'.$list["SoupName"].'Cup"></td>'
            
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="'.$list["SoupName"].'Bowl"></td>'
            '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="'
    .$list["SoupName"].'Mulloy">' 
            
    '</tr>';
    }
    echo (
    $soupCheckboxes);
    ?>
    Maybe something like that... didn't test it.

  9. #9
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I think I figured out the problem. The appropoiate text boxes are not being associated with that particular soup checkbox. There is no relationship between those 3 textboxes and that one checkbox on the same line. How can I relate the 3 textboxes with that individual checkbox to ensure the correct values are always displayed on the correct line?
    TAKE A WALK OUTSIDE YOUR MIND.

  10. #10
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Does this make sense, I may not be explaining it correctly? Anybody know how to fix this and add a relationship to the textboxes and appropiate checkbox?
    TAKE A WALK OUTSIDE YOUR MIND.


Bookmarks

Posting Permissions

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