Witam ma taki problem chciał bym żeby do użytkowników pojawiających się w tabeli pojawiały się przyciski które umożliwią usunięcie ich z bazy danych. Dodatkowo pytając czy napewno chcesz usunąć użytkownika. Kompletnie nie wiem jak się za to zabrać. Proszę o jakąś podpowiedź :)
Kod PHP
<!DOCTYPE html>
<html>
<head>
<title> Formularze </title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="box1">
<div id="boxL"></div>
<div id="boxP">
<table style="border: solid; border-color: yellow; font-color:yellow; margin-left: 8%; margin-top: -10%;">
<tr>
<td id="id">ID</td>
<td id="email">EMAIL</td>
<td id="state">STATE</td>
</tr>
<div>
<?php
$logged = false;
$mysqli = new mysqli('localhost', 'root', null, 'school');
if ($mysqli->connect_errno) {
echo 'Błąd połączenia z bazą danych';
die;
}
$fields = ['login', 'password'];
foreach ($fields as $field) {
if (isset($_POST[$field]) && $_POST[$field] == '') {
$errors[$field] = 'To pole nie może być puste';
}
}
if (isset($_POST['log'])) {
if (isset($_POST['login']) && isset($_POST['password'])) {
$query = 'SELECT * FROM users WHERE state = 200 AND login = "' . $_POST['login'] . '"';
$result = $mysqli->query($query)
->fetch_array(MYSQLI_ASSOC);
if (isset($result['password']) && password_verify($_POST['password'], $result['password'])) {
$logged = true;
} else {
$errors['main'] = 'Błędne dane logowania';
}
}
} elseif (isset($_POST['sign'])) {
if (strlen($_POST['login']) < 5 || strpos($_POST['login'], '@') == false) {
$errors['login'] = 'Login jest nieprawidłowy.';
}
if (strlen($_POST['password']) < 5) {
$errors['password'] = 'Hasło jest nieprawidłowe.';
}
if (!isset($errors)) {
$duplicate = $mysqli->query('SELECT COUNT(id) as counter FROM users WHERE login = "' . $_POST['login'] . '"')
->fetch_array(MYSQLI_ASSOC);
if ($duplicate['counter'] == 0) {
$query = 'INSERT INTO users (login, password, state) VALUES ("' . $_POST['login'] . '", "' . password_hash($_POST['password'], PASSWORD_DEFAULT) . '", 200)';
$mysqli->query($query);
} else {
$errors['login'] = 'Podany login jest już zajęty.';
}
}
}
$wynik = $mysqli->query("SELECT `id`, `login`, `state` FROM `users`");
while ($row = mysqli_fetch_array($wynik)) {
if($row['state']==150){
$row['state'] = "nieaktywny";
}
else if($row['state']==200){
$row['state'] = "aktywny";
};
echo '<tr>' .'<td>'. $row['id'] . '</td>' . '<td>'. $row['login'] . '</td>' .'<td>'. $row['state'] .'</td>'. '</tr>';
echo "<br>";
}
?>
</div>
</table>
<form action="#" method="POST">
<p>
<label for="login"></label>
<input type="text" id="login" name="login" placeholder="Login" value="<?php echo isset($_POST['login']) ? $_POST['login'] : ''; ?>">
<strong style="color: red; font-size: 0.8em; display: block; margin-left: 25%;"><?php echo isset($errors['login']) ? $errors['login'] : ''; ?></strong>
</p>
<p>
<label for="pass"></label>
<input type="password" id="pass" name="password" placeholder="Hasło">
<strong style="color: red; margin-left: 25%; font-size: 0.8em; display: block;"><?php echo isset($errors['password']) ? $errors['password'] : ''; ?></strong>
</p>
<input type="submit" id="log" name="log" value="Zaloguj">
<input type="submit" id="sign" name="sign" value="Zarejestruj">
</form>
<?php if (isset($errors['main'])) { ?>
<p> <strong style="color: red; font-size: 20px; margin-top: 10%; margin-left:5%; display: block;"> <?php echo $errors['main']; ?> </strong> </p>
<?php } elseif ($logged === true) { ?>
<p style="color: green;"> Użytkownik został zalogowany</p>
<?php } ?>
<input type="hidden" name="id" value="<tutaj id>" />
<input type="submit" value="Usuń" />
</body>
</html>
Kod Css
body
{
margin: 0;
background-color: white;
color: black;
font-family: 'Open Sans', sans-serif;
font-size: 17px;
}
#boxP
{
height: 500px;
width: 350px;
background-color: #696969;
float: left;
box-shadow: 14px 10px 14px;
}
#boxL
{
float: left;
height: 500px;
width: 350px;
background-color: #1f1f14;
box-shadow: 13px 10px 14px;
}
#box1
{
height: 400px;
width: 800px;
position: absolute;
left: 50%;
top: 45%;
transform: translate(-50%,-50%);
}
#login
{
width: 170px;
height: 35px;
color: black;
background-color: white;
margin-top: 10%;
margin-left: 25%;
text-align: center;
border-radius: 10px;
border: hidden;
}
#pass
{
width: 170px;
height: 35px;
color: black;
background-color: white;
margin-top: 5%;
text-align: center;
border-radius: 10px;
border: hidden;
margin-left: 25%;
}
#log
{
height: 30px;
width: 80px;
background-color: white;
margin-top: 25%;
margin-right: 5%;
margin-bottom: 5%;
float: right;
border-radius: 10px;
border: hidden;
font-size: 15px;
}
#log:hover
{
height: 30px;
width: 80px;
background-color: yellow;
margin-top: 25%;
margin-right: 5%;
margin-bottom: 5%;
float: right;
border-radius: 10px;
border: hidden;
font-size: 15px;
}
#sign
{
height: 30px;
width: 80px;
background-color: white;
margin-top: 25%;
margin-right: 5%;
margin-bottom: 5%;
float: right;
border-radius: 10px;
border: hidden;
font-size: 15px;
}
#sign:hover
{
height: 30px;
width: 80px;
background-color: yellow;
margin-top: 25%;
margin-right: 5%;
margin-bottom: 5%;
float: right;
border-radius: 10px;
border: hidden;
font-size: 15px;
}
#id{
border-bottom: solid;
}
#email{
border-bottom: solid;
}
#state{
border-bottom: solid;
}