"selectedValue" anahtarı ile POST ediyoruz şu şekilde kullanabilirsiniz;
<?php
if (isset($_POST["selectedValue"]))
{
$selectedValue = $_POST["selectedValue"];
// Burada yapmak istediğiniz işlemleri gerçekleştirebilirsiniz
// Örneğin veritabanına kaydetmek veya cevap oluşturmak
// Örnek cevap:
echo "Seçilen değer: " . $selectedValue;
}
else
{
echo "Seçilen değer alınamadı.";
}
hocam olmadı yaptıklarınızın aynısını yaptım :
<script>
document.addEventListener("DOMContentLoaded", function() {
const selectElement = document.getElementById("userStatus");
selectElement.addEventListener("change", function() {
const selectedValue = selectElement.value;
// Veriyi PHP'ye gönder
sendDataToPHP(selectedValue);
});
});
function sendDataToPHP(value) {
fetch("users.php", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: "selectedValue=" + encodeURIComponent(value),
})
.then(response => response.text())
.then(data => {
console.log(data);
})
.catch(error => {
console.error("Hata oluştu:", error);
});
}
</script>
<select class="form-select" id="userStatus">
<option value="aktif" class="text-success">Aktif</option>
<option value="ban" class="text-success">Ban</option>
</select>
if (isset($_POST["selectedValue"])){
$selectedValue = $_POST["selectedValue"];
$updateUserStatus = $db->query("UPDATE `users` SET `status` = '$selectedValue' WHERE `users`.`id` = $userId");
$count = $updateUserStatus->rowCount();
if ($count > 0) {
echo "<script>
Swal.fire({
icon: 'success',
title: 'Başarılı',
text: 'Üye Durumu Değiştirildi'
})
setTimeout(()=>{
window.location = 'uyeler'
},2000)
</script>";
} else {
echo "<script>
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Üye durumu değiştirilemedi'
})
setTimeout(()=>{
window.location = 'uyeler'
},2000)
</script>";
}
}
?>