Ik ben hier al eerder mee bezig geweest, maar het is niet gelukt om dat aan de praat te krijgen.
Na verder zoeken op internet kwam ik dit script tegen die zou moeten doen wat ik nodig heb, maar het werkt niet.
Wat ik dus wil is de waarde van het listmenu wijzigen in de database zonder dat de pagina opnieuw geladen wordt.
Wie wil me helpen om dit werkend te krijgen, ik zou er erg mee geholpen zijn.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var selectValue = $('#selectBoxID').val();
// post to php script
$.ajax({
type: 'POST',
url: 'insertdetailed.php',
data: { selectValueBox: selectValue }
});
});
</script>
</head>
<body>
<form id="update_db" name="update_db" method="post">
<select id="selectBoxID" onselect="saveToDatabase()">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
</select>
<input type="hidden" name="id" id="1">
</form>
</body>
</html>
<?php
if(isset($_POST['selectValueBox'])){
$connectie = new mysqli("localhost", "xxxxxx", "xxxxxx", "xxxxxx");
// update de score
$sql_update = "UPDATE obs_scores SET score = '".$_POST['selectValueBox']."' WHERE id= '".$_POST['id']."'";
if (mysqli_query($connectie, $sql_update)) {
echo 'SUCCESS';
print $sql_update;
} else {
echo 'FAILED';
print $sql_update;
}
}
?>