I made a system where I can input data, and show it in a table. I also made a check for the input (empty or not) but now my data doesnt get stored anymore. What can I do to fix this? Ive tried alot, a link to a different question with the answer would be good as well. Here is my code:
<?php
if(isset($_POST['vtprof']))
{
if (empty($_POST["tun"])) {
echo ('<br>Er zijn velden leeg');
} elseif (empty($_POST["tpw"])) {
echo ('<br>Er zijn velden leeg');
} elseif (empty($_POST["tnm"])) {
echo ('<br>Er zijn velden leeg');
} elseif (empty($_POST["tbs"])) {
echo ('<br>Er zijn velden leeg');
} elseif (empty($_POST["tpl"])) {
echo ('<br>Er zijn velden leeg');
} elseif (empty($_POST["tps"])) {
echo ('<br>Er zijn velden leeg');
} elseif (empty($_POST["tgd"])) {
echo ('<br>Er zijn velden leeg');
} elseif (empty($_POST["tbd"])) {
echo ('<br>Er zijn velden leeg');
} else {
$v_username = $_POST['tun'];
$v_password = $_POST['tpw'];
$v_name = $_POST['tnm'];
$v_basis = $_POST['tbs'];
$v_positie = $_POST['tps'];
$v_plaatsing = $_POST['tpl'];
$v_geboortedatum = $_POST['tgd'];
$v_startdatum = $_POST['tsd'];
$query = "INSERT INTO users
VALUES (0, '$v_username', '$v_password',
'$v_name', '$v_geboortedatum', '$v_startdatum',
'$v_basis', '$v_positie', '$v_plaatsing')";
$stm = $con->prepare($query);
if ($stm->execute()) {
header("location:editprofiles.php");
} else {
echo ('Aanmaken mislukt');
}
I think you have a Typo by checking your $_POST variables.
you check for
elseif (empty($_POST["tbd"]))
but want to get
$v_startdatum = $_POST['tsd'];
So the ckecking can't be true.
But please consider the advices in the comments.