ok rozumiem zatem wstawiam kod tutaj
CODE
<?php
session_start();
include 'polaczenie.php';
$characterName = '';
$selectedRace = '';
$selectedClass = '';
$selectedProfession = '';
$pdPoints = 0;
if (isset($_SESSION['character_name'])) {
$characterName = $_SESSION['character_name'];
}
if (isset($_SESSION['selected_race'])) {
$selectedRace = $_SESSION['selected_race'];
}
if (isset($_SESSION['selected_class'])) {
$selectedClass = $_SESSION['selected_class'];
}
if (isset($_SESSION['selected_profession'])) {
$selectedProfession = $_SESSION['selected_profession'];
}
if (isset($_SESSION['pd_points'])) {
$pdPoints = $_SESSION['pd_points'];
}
// Sprawdź, czy istnieje już wpis w tabeli dice_results_temp dla danego user_id i imienia/nazwiska postaci
if (isset($_SESSION['user_id']) && isset($_SESSION['character_name'])) {
$user_id = $_SESSION['user_id'];
$chName = $_SESSION['character_name'];
$queryCheckEntry = "SELECT * FROM dice_results_temp WHERE user_id = '$user_id' AND ch_name = '$chName'";
$resultCheckEntry = mysqli_query($conn, $queryCheckEntry);
if ($resultCheckEntry && mysqli_num_rows($resultCheckEntry) > 0) {
// Wpis już istnieje, wczytaj istniejące dane
$rowExistingEntry = mysqli_fetch_assoc($resultCheckEntry);
$existingWW = $rowExistingEntry['ww'];
} else {
// Wpis nie istnieje, utwórz nowy wpis
$queryInsertEntry = "INSERT INTO dice_results_temp (user_id, ch_name) VALUES ('$user_id', '$chName')";
$resultInsertEntry = mysqli_query($conn, $queryInsertEntry);
if (!$resultInsertEntry) {
echo "Błąd: Nie udało się utworzyć nowego wpisu.";
exit();
}
}
} else {
echo "Błąd: Brak wymaganych danych sesji.";
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Kreator Postaci - Cechy 2</title>
</head>
<style>
table {
text-align: center;
}
th, td {
padding: 5px;
}
td button {
margin: 0 auto;
}
</style>
<body>
<h1>Kreator Postaci - Cechy 2</h1>
<?php
if (isset($_SESSION['username'])) {
echo '<p>Witaj, ' . $_SESSION['username'] . '!</p>';
}
?>
<p>Imię i nazwisko postaci: <?php echo $characterName; ?></p>
<p>Rasa: <?php echo $selectedRace; ?></p>
<p>Klasa: <?php echo $selectedClass; ?></p>
<p>Profesja: <?php echo $selectedProfession; ?></p>
<p>Suma PD: <?php echo $pdPoints; ?></p>
<p>Żywotność:
<?php
if (isset($_SESSION['user_id']) && isset($_SESSION['character_name'])) {
$user_id = $_SESSION['user_id'];
$chName = $_SESSION['character_name'];
} else {
echo "Błąd: Brak wymaganych danych sesji.";
exit();
}
$queryLifeValue = "SELECT s, w, sw FROM dice_results_temp WHERE user_id = '$user_id' AND ch_name = '$chName'";
$resultLifeValue = mysqli_query($conn, $queryLifeValue);
if ($resultLifeValue && mysqli_num_rows($resultLifeValue) > 0) {
$rowLifeValue = mysqli_fetch_assoc($resultLifeValue);
$lifeValue = $rowLifeValue['s'] + (2 * $rowLifeValue['w']) + $rowLifeValue['sw'];
echo $lifeValue;
} else {
echo "Siła + (2 x Wytrzymałość) + Siła Woli - Wylosuj watości cech aby obliczyć!";
}
?>
</p>
<h2>Cechy Rasy</h2>
<table border="1">
<tr>
<th>Cecha Rasowa</th>
<th>Wartość</th>
</tr>
<?php
$queryCharacteristics = "SELECT DISTINCT characteristic, points FROM characteristic_race WHERE race = '$selectedRace'";
$resultCharacteristics = mysqli_query($conn, $queryCharacteristics);
if ($resultCharacteristics && mysqli_num_rows($resultCharacteristics) > 0) {
while ($row = mysqli_fetch_assoc($resultCharacteristics)) {
echo '<tr>';
echo '<td>' . $row['characteristic'] . '</td>';
echo '<td>' . $row['points'] . '</td>';
echo '</tr>';
}
}
?>
</table>
<h2>Cechy Postaci</h2>
<form method="post" action="">
<table border="1">
<tr>
<th>Wybierz Cechę</th>
<th>Punkty Cechy</th>
</tr>
<?php
if (isset($_SESSION['user_id']) && isset($_SESSION['character_name'])) {
$user_id = $_SESSION['user_id'];
$chName = $_SESSION['character_name'];
} else {
echo "Błąd: Brak wymaganych danych sesji.";
exit();
}
$queryCharacteristicValues = "SELECT ww, us, s, w, i, zw, zr, intel, sw, o FROM dice_results_temp WHERE user_id = '$user_id' AND ch_name = '$chName'";
$resultCharacteristicValues = mysqli_query($conn, $queryCharacteristicValues);
if ($resultCharacteristicValues && mysqli_num_rows($resultCharacteristicValues) > 0) {
$rowCharacteristicValues = mysqli_fetch_assoc($resultCharacteristicValues);
$characteristicNames = array(
'ww' => 'Walka Wręcz',
'us' => 'Umiejętności Strzeleckie',
's' => 'Siła',
'w' => 'Wytrzymałość',
'i' => 'Inicjatywa',
'zw' => 'Zwinność',
'zr' => 'Zręczność',
'intel' => 'Inteligencja',
'sw' => 'Siła Woli',
'o' => 'Ogłada',
);
echo '<tr><td colspan="3">';
// Dodaj listę wyboru cech
foreach ($characteristicNames as $key => $name) {
echo '<tr>';
echo '<td>';
echo '<select name="selected_characteristics[' . $key . ']" class="characteristic-select">';
echo '<option value="">Wybierz</option>'; // Opcja "Wybierz" jako domyślna
// Dla każdej cechy, sprawdź, czy jest dostępna
foreach ($characteristicNames as $optionKey => $optionName) {
if ($optionKey === $key) {
echo '<option value="' . $optionKey . '">' . $optionName . '</option>';
} else {
$disabled = in_array($optionKey, array_keys($selectedCharacteristics)) ? 'disabled' : '';
echo '<option value="' . $optionKey . '" ' . $disabled . '>' . $optionName . '</option>';
}
}
echo '</select>';
echo '</td>';
echo '<td>' . $rowCharacteristicValues[$key] . '</td>';
echo '</tr>';
}
?>
</table>
</form>
<p>Czy akceptujesz swój los?</p>
<form method="post" action="">
<button type="submit" name="accept" value="yes">Tak</button>
<button type="submit" name="accept" value="no">Nie</button>
</form>
<?php
if (isset($_SESSION['user_id']) && isset($_SESSION['character_name'])) {
$user_id = $_SESSION['user_id'];
$chName = $_SESSION['character_name'];
} else {
echo "Błąd: Brak wymaganych danych sesji.";
exit();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['accept'])) {
$acceptChoice = $_POST['accept'];
if ($acceptChoice === 'yes') {
// Pamiętaj o zabezpieczeniu przed SQL Injection!
// Przykład polecenia SQL do aktualizacji cech w tabeli dice_results_temp
$updateQuery = "UPDATE dice_results_temp SET
ww = '{$selectedCharacteristics['ww']}',
us = '{$selectedCharacteristics['us']}',
s = '{$selectedCharacteristics['s']}',
w = '{$selectedCharacteristics['w']}',
i = '{$selectedCharacteristics['i']}',
zw = '{$selectedCharacteristics['zw']}',
zr = '{$selectedCharacteristics['zr']}',
intel = '{$selectedCharacteristics['intel']}',
sw = '{$selectedCharacteristics['sw']}',
o = '{$selectedCharacteristics['o']}'
WHERE user_id = '$user_id' AND ch_name = '$chName'";
$updateResult = mysqli_query($conn, $updateQuery);
// Dodaj 25 PD do aktualnej wartości PD
$pdPoints += 25;
$_SESSION['pd_points'] = $pdPoints;
// Przekieruj na character_talents.php
header("Location: character_talents.php");
exit();
} elseif ($acceptChoice === 'no') {
// Przekieruj na character_characteristic_2.php
header("Location: character_characteristic_2.php");
exit();
}
}
}
?>
<script>
const selectElements = document.querySelectorAll('.characteristic-select');
selectElements.forEach(selectElement => {
selectElement.addEventListener('change', () => {
const selectedValue = selectElement.value;
selectElements.forEach(otherSelect => {
if (otherSelect !== selectElement) {
const optionToRemove = otherSelect.querySelector(`option[value="${selectedValue}"]`);
if (optionToRemove) {
optionToRemove.remove();
}
}
});
});
});
</script>
</body>
</html>