0
$result = mysql_query('SELECT * FROM teams');

while($row = mysql_fetch_array($result))
{
  $team= $row['team'];
  $goals= $row['goals'];
  $squadsize= $row['squadsize'];
  $league= getTheirLeague($team);
  echo $team. "</br>";
  echo "Goals Scored " . $goals. "</br>";
  echo "League " . $league. "</br>" . "</br>";

  <form method="POST" action="football.php">
    <button type="button">Edit</button>
    <button type="button">Remove</button>
  </form>
}

I am trying to add a remove and edit feature to my teams, for every team i print out i have a form being printed with 2 buttons. What i am unsure of is how i can tie the button clicks up to the definitive team that the button belongs too.

0

1 Answer 1

1

As each row (team) gets its own form, simply add a hidden field with the team identifier (assuming $row['team'] for this example).

Please note that IE has terrible <button> support in forms. I'd advise using submit inputs...

<form method="POST" action="football.php">
    <input type="hidden" name="team"
        value="<?php echo htmlspecialchars($row['team']) ?>">
    <input type="submit" name="edit" value="Edit">
    <input type="submit" name="remove" value="Remove">
</form>

You can then tell which team form was submitted by checking $_POST['team'] and which button was pressed using...

if (isset($_POST['edit']) { 
    // edit clicked
}

if (isset($_POST['remove']) {
    // remove clicked
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.