Nadat het formulier is verzonden, info is opgeslagen in de DB krijg ik de melding dat bepaalde error-variabel niet bestaat, raar toch?
Onderstaande code is van het formulier.
Btw; ik weet dat het niet veilig is en dit is voor mij versie 1!
<?php
include('Inc/config.inc.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Controleer de voornaam:
$voornaam= trim($_POST['voornaam']);
if (empty($voornaam)) {
$vnerror = "Voornaam mag niet leeg zijn";
}
// Controleer de achternaam:
$achternaam= trim($_POST['achternaam']);
if (empty($achternaam)) {
$anerror = "Achternaam mag niet leeg zijn";
}
// Controleer de bedrijfsnaam:
$bedrijfsnaam = trim($_POST['bedrijfsnaam']);
if (empty($bedrijfsnaam)) {
$bnerror = "Bedrijfsnaam mag niet leeg zijn";
}
// Controleer het mailadres:
$mailadres = trim($_POST['mailadres']);
if (empty($mailadres)) {
$merror = "Mailadres mag niet leeg zijn";
}
// Controleer het wachtwoord:
$wachtwoord = trim($_POST['wachtwoord']);
if (empty($wachtwoord)) {
$werror ="Wachtwoord mag niet leeg zijn";
}
// Controleer de functie:
$functie = trim($_POST['functie']);
if (empty($functie)) {
$ferror = "Functie mag niet leeg zijn";
}
// Controleer of het mailadres al bestaat
require('Inc/db-connection.php');
$checkingmail = mysqli_query($dbc, "SELECT * from Behandelaars where Mailadres= '$mailadres'") or die(mysqli_error($dbc));
if(mysqli_num_rows($checkingmail) > 0) {
echo "Het mailadres is al in gebruik";
} else {
if (empty($vnerror && $anerror && $bnerror && $merror && $werror && $ferror)) {
$hashed_passcode = password_hash($wachtwoord, PASSWORD_DEFAULT);
$query = "INSERT INTO Behandelaars (Voornaam, Achternaam, Bedrijfsnaam , Mailadres , Wachtwoord, Functie, DatumActief, RegistratieDatum )";
$query.= "VALUES (?, ?,?, ?, ?, ?, NOW(), NOW())";
$q = mysqli_stmt_init($dbc);
mysqli_stmt_prepare($q,$query);
mysqli_stmt_bind_param($q, 'ssssss', $voornaam, $achternaam, $bedrijfsnaam, $mailadres, $hashed_passcode,$functie);
mysqli_stmt_execute($q);
if (mysqli_stmt_affected_rows($q) == 1){
header ("Location: index.php");
exit();
} else {
echo "De computer heeft het druk en probeer het later nog eens!";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="Inc/main.css">
<title>Registreer pagina</title>
</head>
<body>
<div class="container">
<div class="regform">
<form action="register.php" method="POST">
<fieldset><legend>Registreer formulier</legend>
<label for="Voornaam">Voornaam</label><br />
<input type="text" id="voornaam" name="voornaam" value="<?php if (isset($_POST['voornaam']))echo htmlspecialchars($_POST['voornaam'], ENT_QUOTES); ?>" ><?php if (isset($vnerror)) { echo $vnerror; } ?><br />
<label for="achternaam">Achternaam</label><br />
<input type="text" id="achternaam" name="achternaam" value="<?php if (isset($_POST['achternaam']))echo htmlspecialchars($_POST['achternaam'], ENT_QUOTES); ?>" ><?php if (isset($anerror)) { echo $anerror; } ?><br />
<label for="bedrijfsnaam">Bedrijfsnaam</label><br />
<input type="text" id="bedrijfsnaam" name="bedrijfsnaam" value="<?php if (isset($_POST['bedrijfsnaam']))echo htmlspecialchars($_POST['bedrijfsnaam'], ENT_QUOTES); ?>" ><?php if (isset($bnerror)) { echo $bnerror; } ?><br />
<label for="Mailadres">Mailadres</label><br />
<input type="text" id="mailadres" name="mailadres" value="<?php if (isset($_POST['mailadres']))echo htmlspecialchars($_POST['mailadres'], ENT_QUOTES); ?>" ><?php if (isset($merror)) { echo $merror; } ?><br />
<label for="wachtwoord">Wachtwoord</label><br />
<input type="password" id="wachtwoord" name="wachtwoord" value="<?php if (isset($_POST['wachtwoord']))echo htmlspecialchars($_POST['wachtwoord'], ENT_QUOTES); ?>" ><?php if (isset($werror)) { echo $werror; } ?><br />
<label for="functie">Functie</label><br />
<input type="text" id="functie" name="functie" value="<?php if (isset($_POST['functie']))echo htmlspecialchars($_POST['functie'], ENT_QUOTES); ?>" ><?php if (isset($ferror)) { echo $ferror; } ?><br />
<input type="submit" value="Verzenden">
<p>Al een geregistreerd account?<a href="login.php">Login</a></p>
</fieldset>
</form>
</div>
<div class="regformplaatje"></div>
</div>
</body>
</html>