How do I save values from one table into another table using a dropdown list box

Hi, I’m new to PHP nd this is a project we’ve been given to do this semster. I have three tables, players,fixtures and team. Now what I want/need the code to do is the following-
The user is presented with a table that has all the field names of the table team listed. Next to eeach field nama they can then select a players name from a drop down list box which is popu;ated with names from the players table. When the user clicks submit, the player name next to the corresponding field name for team gets saved into the team table as the value for that field.
My problem is this - I have no idea how to assign the value from the drop down list to the corresponding field name in the team table… Please help!


<?php //Include the database connection information. include('connect.php'); //Start the session. session_start(); //Get fixture id and declare variables. $fixture_id=$_GET['fixture_id']; $select=$_GET['update']; $submit=$_POST['submit']; //Because the form method at the end is POST if($select=='yes'){ //Team selection table with sdrop down boxes. //Table header. echo ""; echo " fixture_id: '$fixture_id'"; echo ""; //table. $query = mysql_query("SELECT * FROM `team`"); //Display the field names of the team table. //Loop over all result rows. while($row = mysql_fetch_assoc($query)) { //Loop over all fields per row. foreach($row as $field => $value) { if($field != selection_id && $field != fixture_id){ echo ''; echo ''; } } } echo ""; echo "
Position Player<td
' . htmlentities($field) . ' ' . htmlentities($value ) . ''; $sql = "SELECT name FROM players"; $result = mysql_query($sql); //While loop to echo out the player names into the select box. echo ""; while ($row = mysql_fetch_array($result)) { echo "" . $row['name'] . ""; } echo ''; echo '
<input type=submit name='submit' value='Save team'
"; //Table ends outside loop. echo ""; //Nested if statement to save data to the db. if($submit=='Save team'){ //save fixture_id. $sql=mysql_query("INSERT INTO team (fixture_id) SELECT fixture_id FROM fixtures WHERE fixture_id='$fixture_id'") or die(mysql_error()); } }else{ //Display fixtures for which a team can be selected. //Get fixtures from database. $sql= mysql_query("Select * FROM fixtures") or die(mysql_error()); //Table header. echo ""; echo ""; //Loop through the results of the database query, displaying them in the table. while($row=mysql_fetch_array($sql)){ //While loop starts. $fixture_id=$row['fixture_id']; //fixture id to use later. $opponents=$row['opponents']; $date=$row['date']; $venue=$row['venue']; //End loop. echo ""; } echo "
Opponents Date Venue Action
$opponents $date $venue Select Team
"; //Table ends outside loop. echo ""; } ?>


Project can be done easily! But, can you provide the structure of the these 3 tables, and you didnt mention the use of fixture table.

Sponsor our Newsletter | Privacy Policy | Terms of Service