Information
I made a PHP script that connects to my database and creates a record in my database. This works. Now, I added a simple form to this page and I want to make a record in my database based on the input that a user gives.
The PHP script without the form:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "detachering";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO medewerkers (voornaam, achternaam, leeftijd, uurloon, opleidingsniveau)
VALUES ('test', 'user', '20', '192', 'HBO')";
if ($conn->query($sql) === TRUE) {
echo "Medewerker is aangemaakt";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
This is the form that I want to add to it:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form class="" action="index.html" method="post">
<input type="text" name="voornaam" placeholder="Voornaam">
<input type="text" name="achternaam" placeholder="Achternaam">
<input type="text" name="leeftijd" placeholder="Leeftijd">
<input type="text" name="uurloon" placeholder="Uurloon">
<input type="text" name="opleidingsniveau" placeholder="Opleidingsniveau">
<button type="submit" name="button">Save</button>
</form>
</body>
</html>
I personally think that it should be something like:
INSERT INTO medewerkers (voornaam, achternaam, leeftijd, uurloon, opleidingsniveau)
VALUES ('POST_['voornaam']', 'POST_['achternaam']', 'POST_['leeftijd']', 'POST_['uurloon']', 'POST_['opleidingsniveau']');
I haven't done much in PHP, so any help is greatly appreciated!