Jump to content

passing an array of data from a form


harlequeen

Recommended Posts

Hi

 

I am trying to pass a set of points for a selection of teams from a form which I have.  In the form I have each qualifying team with a select statement allowing me to choose between 0 & 7 points.  How do i then get the information into my points section for each team in my table?

 

I have the array of teams printed with the dropdown with the points available and the teams id number, but I don't know how to get the points into the correct teams' section in the database.

 

Can anyone help please.  I have tried to look at some tutorials but I can only really find ones on checkboxes and they don't seem to help me.  I'm not great at php/mysql as I'm trying to teach myself.  If someone can point me in the right direction for a turorial that would be a great help (the simpler, the better).

 

thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/167400-passing-an-array-of-data-from-a-form/
Share on other sites

I think what you want to do is give the select statements a name such that they will be returned as an array with the team ID as the index. Here is what the HTML output would look like:

Team 1 <select name="team_points[1]">

When you create these in PHP I would assume you are looping through the teams and writing the data. The PHP code would look something like this:

echo "$teamName <select name="team_points[$teamID]">";

 

In the processing page you can simply loop through the POST array value to get the team IDs and Points submitted

foreach ($_POST['team_points'] as $teamID => $teamPoints)
{
    echo "Team ID: $teamID, Team Points: $teamPoints <br> ";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.