So the PHP script is actually having a connection with the server, but somehow the database at localhost doesn't fill. What did I possibly do wrong?
script.php
<?php
$link = mysqli_connect("127.0.0.1", "root", "", "testdb");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is
great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
$klas = isset($_POST['klasDown']);
$naam = isset($_POST['naamTxt']);
$stmt = $link->prepare("INSERT INTO resultaten (Klas, Naam) VALUES (?, ?");
if (!$stmt) {
echo "false";
} else {
$stmt->bind_param("ss", $klas, $naam);
$stmt->execute();
}
mysqli_close($link);
?>
HTML:
<form id="myForm" method="post" action="script.php">
Naam: <input name="naamTxt" type="text" maxlength="512"
id="naamTxt" class="searchField"/> <br>
Klas: <select name="klasDown">
<option value="H4A" selected="selected">H4A</option>
<option value="H4B" >H4B</option>
<option value="H4C">H4C</option>
<option value="H4C">H4D</option>
<option value="H4C">V4A</option>
<option value="H4C">V4B</option>
<option value="H4C">V4C</option>
<option value="H4C">V4D</option>
</select>
<div class="row">
<div class="col-4">1. Kies 1/5 </div>
<div class="col text-center"><input type="radio" name="v1" id="v1_1"
value="Helemaal mee oneens"></div>
<div class="col text-center"><input type="radio" name="v1" id="v1_2"
value="Deels oneens"></div>
<div class="col text-center"><input type="radio" name="v1" id="v1_3"
value="Neutraal"></div>
<div class="col text-center"><input type="radio" name="v1" id="v1_4"
value="Deels mee eens"></div>
<div class="col text-center"><input type="radio" name="v1" id="v1_5"
value="Helemaal mee eens"></div>
</div>
<input type= "submit" style="text-align: center"
onclick="bereken()">
</form>
^ Above is the Html Form
Bereken() function:
function bereken() {
var e = 0;
var c = 0;
if(document.getElementById('v1_1').checked) {
c = c - 0
}else if(document.getElementById('v1_2').checked) {
c += 1;
}else if(document.getElementById('v1_3').checked) {
c += 2;
}else if(document.getElementById('v1_4').checked) {
c += 3;
}else if(document.getElementById('v1_5').checked){
c += 4;
}
var klas = li.options[li.selectedIndex].value;
var naam = document.getElementById('searchTxt').value;
alert(klas + ", " + naam);
}
^ This is the Javascript bereken() function . Apparently too much code, so have to add some text.
mysqliis significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_queryinterface. Before you get too invested in the procedural style it’s worth switching over. Example:$db = new mysqli(…)and$db->prepare("…”)The procedural interface is an artifact from the PHP 4 era whenmysqliAPI was introduced and should not be used in new code. You're mixing and matching styles here for no apparent reason. Try and use the newer form exclusively.