0

I have a table with some information from my database. I have buttons next to each row in the table. If the button is clicked it should send an email to the user. I can give each button a unique value but can not have this value in the if isset.... How should i get the value of the button name to be variable and how could i get the value at the end of my url.

echo "<table>";
echo "<tr><td>Naam</td><td>EmailAdress</td><td>Datum</td><td>Type</td><td>Producent</td><td>SerieNummer</td><td>    imei</td><td>Manager</td><td>bevestigd</td></tr>";
while($row = mysqli_fetch_row($result)){
$sqlid = "SELECT Bevestigd FROM tbl_bevestiging WHERE IDbewijs = " . $row[0];
$resultid = mysqli_query($conn, $sqlid);
$row2 = mysqli_fetch_row($resultid);
echo "<tr><td>" . $row[1] . "</td><td>" . $row[2] . "</td><td>" . $row[3] . "</td><td>" . $row[4] . "</td><td>" . $row[5] . "</td><td>" . $row    [6] . "</td><td>" . $row[7] . "</td><td>" . $row[8] . "</td><td>" . $row2    [0] . "</td><td><form method=\"post\"><input name=\"" . $row[0] . "\"     type=\"submit\" value=\"" . $row[0] . "\"</form></td></tr>";
}
echo "</table>";

if (isset($_POST[$row[0]])){
$admin_email = "adminmail@mail.com," . $row[2];
mail($admin_email, "Ontvangstbewijs geleverde hardware     herverstuurd", "url?id=" . $row     [0] , "From:" . "example@email.com");
mysqli_close($conn);
}
?>
landervl
  • 13
  • 4
  • Possible duplicate of [Send value of submit button when form gets posted](http://stackoverflow.com/questions/22579616/send-value-of-submit-button-when-form-gets-posted) – Ionut Necula Apr 27 '16 at 09:21
  • **WHOA!!!** **NEVER** put a database query inside of *any* kind of programming loop! That is a *very* clear sign that you don't yet command enough understanding of SQL. – John Apr 27 '16 at 09:49

1 Answers1

0

Theres a few things I think are worth pointing out firstly.

  1. Table header tags should be in a THEAD tag. See example here.
  2. Try and avoid SQLs within a loop. If possible create a SQL that does everything for you to reduce the number of queries sent to MySQL.

Ok back to your question. Personally, what I would do is have a FORM tag in a TD tag. This way each button can have it's own unique id set in a hidden INPUT tag.

For example:

<tr>
<td>
<form action="[[YOUR-PHP-FILE]]" method="post">
<input type="hidden" name="id" value="[[ID]]" />
<input type="submit" value="Submit" />
</form>
</td>
</tr>

That way you don't need to focus on the submit button but rather the id.

rharvey
  • 1,987
  • 1
  • 28
  • 23