-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange-amount2.php
33 lines (33 loc) · 1.46 KB
/
change-amount2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
if (isset($_POST['user']) && isset($_POST['money'])) {
include("db-connection.php");
$sql = "SELECT DISTINCT(login) FROM user ORDER BY login";
$sql_result = mysqli_query($db, $sql);
$usernames = [];
while ($row = mysqli_fetch_row($sql_result)) {
$usernames[] = $row;
}
$counter = count($usernames);
foreach ($usernames as $username) {
foreach ($username as $user) {
if ($user == $_POST['user']) {
if ($_POST['money'] >= 0) {
$sql_balance = "UPDATE user SET balance = '" . $_POST['money'] . "' WHERE login = '" . $_POST['user'] . "'";
if ($db->query($sql_balance) === TRUE) {
echo "<div class='alert alert-success' role='alert'><h3 class='h4 mb-3'>🎈 Pomyślnie zmieniono balans!</h3></div>";
} else {
echo "<div class='alert alert-danger' role='alert'><h3 class='h4 mb-3'>❌ Nie udało się zmienić balansu</h3></div>";
}
} else {
echo "<div class='alert alert-danger' role='alert'><h3 class='mb-3 h3'>❌ Nie można wprowadzić ujemnego balansu</h3></div>";
}
} else {
$counter--;
}
}
}
if ($counter == 0) {
echo "<div class='alert alert-danger' role='alert'><h3 class='mb-3 h3'>❌ Taka nazwa użytkownika nie istnieje</h3></div>";
}
mysqli_close($db);
}