Results 1 to 4 of 4

Thread: Form Data

  1. #1
    Join Date
    Dec 2003
    Posts
    37

    Unanswered: Form Data

    Hi all

    This has been driving me crazy for weeks no matter what I do I can't get the result I want.

    I have a table with a form on it. the form is loop for the number off Members (in my test this is 7)
    and the user enters a score for each member.

    The form then passes the data to a new page for proccessing. This is where it all falls to pieces.
    I can see the data in the address bar but when I try any loop I can only ever display the last results.

    the output should be

    Mem=1 array = a
    Mem=2 array = b
    Mem=3 array = c etc...

    The data that passes over from the form to the form handling page is...

    Code:
    show.php?Mem=1&array=a&Mem=2&array=b&Mem=3&array=c&Mem=5&array=d&Mem=6&array=e&Mem=7&array=f
    and the form i'm using is...

    Code:
    $list = "<table border =\"1\"><tr><th>Forename</th>";
    $list.= "<th>Surname</th>";
    $list.= "<th>Handicap</th>";
    $list.= "<th>Edit</th>";
    $list.= "<th>Points</th></tr>";
    $list.="<form action=\"show.php\" ";
    $list.="method =\"get\">";
    
    
    while ($row= mysql_fetch_array($rs) )
    {
    
    $Mem = $row["Mem_Id"];
    
    $list.= "<tr>";
    $list.= "<td>".$row["Forename"]."</td>";
    $list.= "<td>".$row["Surname"]."</td>";
    $list.= "<td>".$row["Hcap"]."</td>";
    $list.= "<td> <input type=\"text\" name=\"Mem\" value=\"$Mem\">  </td>";
    $list.= "<td> <input type=\"text\" name=\"array\" value=\"$array[array]\"> </td>";
    
    }
    
    
    	
    $list.= "</table>";
    
    $list.= "<input type=\"submit\" value=\"Submit\">";
    $list.= "</form>";
    	echo($list);
    
    ?>

    Thanks

    JD

  2. #2
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Try the following -
    PHP Code:
    $list.= "<tr>";
    $list.= "<td>".$row["Forename"]."</td>";
    $list.= "<td>".$row["Surname"]."</td>";
    $list.= "<td>".$row["Hcap"]."</td>";
    $list.= "<td> <input type=\"text\" name=\"Mem[]\" value=\"$Mem\">  </td>";
    $list.= "<td> <input type=\"text\" name=\"array[]\"> </td>";
    $list.= "</tr>"// add this to finish row tag 
    This has the following changes from your code -
    From: name=\"Mem\" To: name=\"Mem[]\" - this causes an array to be used instead of a single name. With a single name, the last value that is assigned is what you get out.

    From: name=\"array\" value=\"$array[array]\" To: name=\"array[]\" - same reason as for Mem[], I removed the value portion as I assume this is for entering the points and there are no initial values (your while loop does not manipulate $array[array] in any way.)

    If you use the following code in your form processing code, you can see what you are receiving in the $_GET variable in each case -
    PHP Code:
    echo "<br />Foreach GET data -<br />";
    foreach (
    $_GET as $key => $value) {
        if (
    is_array($value)){
            foreach (
    $value as $key2 => $value2) {
                echo 
    "ArrayKey: ".$key."[$key2], Value: ".nl2br($value2)."<br />";
            }
        } else {
        echo 
    "Key: $key, Value: ".nl2br($value)."<br />";
        }


  3. #3
    Join Date
    Dec 2003
    Posts
    37
    dbmab once again thank you very much !!!!

    Your code worked perfectly and I was able to get the data to output in the way necessary to update the database with the correct data.

    I am able to start error handling now.

    Cheers

    JD

  4. #4
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Thanks

    And I would like to thank you too

    You posted - a statement of what you are doing, an example of what you are getting and what you expect, what data is being passed, and your code. This was everything that someone not familiar with your application needed in order to come up to speed and provide help. (I actually ran your code with some fabricated data.) Even more importantly, you showed that you have done your work and have spent time troubleshooting before you posted. Your code is basically working and you only needed assistance, which is really about the extend of what forum based help can provide.

Posting Permissions

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