Welcome! Log In Create A New Profile

Advanced

Using radio buttons in PHP

Posted by Mariuspienaar 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Using radio buttons in PHP
February 20, 2013 12:01PM
Good day all!

I am using radio buttons in my team selection page,so that the manager can choose for what position which player must play,those radio buttons is for two positions, lets say position 1 and position 2 next to each players row, those data must then be submitted to the database to choose who is on which team.
The data submits to the database but only the last row of the table,not the ones that i choose.
Here is some of my code...

Language: PHP
echo "<table border=';1';>"; echo "<th colspan = ';4';>Team Selection</th>"; echo "<tr>"; echo "<th>player_id</th><th>Name</th><th>Surname</th><th>Position</th>"; echo "</tr>";   while ($row = mysql_fetch_array($result)) { $player_id = $row[';player_id';]; $name = $row[';name';]; $surname = $row[';surname';]; $position = $row[';position';];   echo "<tr><td>$player_id</td><td>$name</td><td>$surname</td><td>$position</td><td>   <form method=';post'; action=';team_selection.php';> <input name=';position1'; type=';radio'; value=';position1';> position1 <input name=';position2'; type=';radio'; value=';position2';> position2 <input type=';submit'; name=';add'; value=';add';> </form> </td></tr>";   }   echo "</table>"; ///////////////this include function is too run the code to add the info on the database.///////////// if(isset($_POST[';add';])) { include(';add_team.php';); }

The include function to add the info is

Language: PHP
$selection_id = $_POST[';selection_id';]; $position1= $_POST[';position1';]; $position2= $_POST[';position2';];   $query = "INSERT INTO teams (selection_id,fixture_id,position1,position2) VALUES (';$selection_id';,';$fixture_id';,';$position1';,';$position2';);";   mysql_query($query);     header (';Location: team_selection.php';);

So the position1 and position2 is added to my database,but not the player in that same row,the player info of the last row is added only.With the add button in the while loop,every row gets a button and i want only that row i click on to be submitted to the database,not the last row.This must be a minor mistake somewhere but cannot seem to find that little bug.
Any help will be appreciated.
avatar
Mac
Re: Using radio buttons in PHP
February 20, 2013 01:53PM
The radio button has the same name throughout e.g. position. Only the value differ. It sends an array, which you need to extract. That is just by the way.

The form and the button is placed wrong. It will just have the last entry from what I can see... put it outside the loop and have just one form

That said, the player's information is not send with the position selected?

Read the tut letter again on the third table


selection_id fixture_id fullback wing center etc.

1 1 3 6 9

where 3 = player_id of the player that has been selected to play at fullback, 6 the player_id of the payer who is to play wing etc.



Watch out for posting too much code..... just what you refer to.
Re: Using radio buttons in PHP
February 20, 2013 10:19PM
Thank you very much for your tips,it helped me so much.
Ja i see,the biggest mistake here what i have done is, i mixed the two tables around while written the pseodocode.spinning smiley sticking its tongue out

And that third table for team selection with the values of |selection_ID,| Fixture_ID,| possition1,| possition2|
All the values under them will be like ------------------------ | 1 | 1 | 2 | 3 | (2 and 3) = Player_id
| 2 | 2 | 4 | 5 | (4 and 5) = Player_id
-----------------------------------------------------------------
So the manager will probably understand the numbers in the table,but the public must also see this table too see who is selected for the team.
Can i change that Player_id's to names and surnames so the public can understood who is playing.The public wont have a clue whats going on with numbers in there.
avatar
Mac
Re: Using radio buttons in PHP
February 21, 2013 11:00AM
It is up to you what you do. It must just work.
Sorry, only registered users may post in this forum.

Click here to login