0
I am making a system, I need it to check the ID of the button that was clicked on the table and perform the action, however it is always picking up the last id, someone knows what can be?
if(isset($_SESSION["mensagemreset1"])):
print $_SESSION["mensagemreset1"];
unset($_SESSION["mensagemreset1"]);
endif;
$id = $_SESSION['idlogin'];
$sql = "SELECT * FROM `char` WHERE account_id='$id'";
$sql = $pdo->query($sql);
foreach ($sql->fetchAll() as $row) {
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['base_level']."/".$row['job_level']."</td>";
echo "<td>".$row['class']."</td>";
echo "<td>".$row['guild_id']."</td>";
echo "<td><button type='submit' class='btn btn-success btn-sm'>Resetar Aparência</button> <button type='button' class='btn btn-info btn-sm'>Resetar Posição<br></button></td>";
echo "<td><input type='hidden' name='id' value=".$row['char_id']."></td>";
echo "</tr>";
}
resetar_appearance.php:
include 'config.php';
require 'Usuario.class.php';
global $pdo;
global $char_id;
echo $_POST['id'];
$statement = $pdo->prepare("UPDATE `char` SET hair=1, hair_color=1, clothes_color=1 WHERE char_id = '$char_id'");
$statement->execute();
//header("Location: inicio.php?pg=meuspersonagens");
$_SESSION['mensagemreset1'] = "<div class='sufee-alert alert with-close alert-success alert-dismissible fade show'>
Aparência do personagem resetada com sucesso.
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>";
I put echo only to test, but it always returns me the last ID.
Check your HTML tags closes before and after your
foreach
, also check via element inspector if there is no php error being printing in the middle of your html;– Helison Santos