I have problem.
I have a code that writes name, surname, birth, church, phone, mail
into the database. However, when the user is under 18, I need to get in touch with my parents using the phonep, mailp
variables.
Here is the counter in JS:
if (birth_date2 <= new Date()) {
if (birth_date <= new Date()) {
$(document).ready(function(){
$("#par").slideUp();
});
<?php $more = 0;?>;
} else {
$(document).ready(function(){
$("#par").slideDown();
});
<?php $more = 1;?>;
}
} else {
alert("Minimum age is 12!");
document.getElementById("birth").value = "";
}
This code determines whether the user is an adult or not:
<?php $more = 0;?>;
Then I have PHP code that I tried to modify using the orientation of the variables:
if($more === 1) {
if(!($_POST["mailp"])) {
$err++;
$echo_er .= "Není vyplněno pole s Emailem rodičů! ";
} else {
$mailp = htmlspecialchars($_POST["mailp"]);
}
if(!($_POST["phonep"])) {
$err++;
$echo_er .= "Není vyplněno pole s telefonním číslem rodičů! ";
} else {
$phonep = htmlspecialchars($_POST["phonep"]);
}
}
$sql = "SELECT * FROM registrace";
$conn->query($sql);
if($more === 1) {
if($err === 0) {
$sql = "INSERT INTO registrace (name, surname, birth, church, phone, mail, phonep, mailp)
VALUES ('$name', '$surname', '$birth', '$church', '$phone', '$mail', '$phone', '$mailp')";
$conn->query($sql);
echo "<p class='pyes'> Registration comlete! </p>";
} else {
echo "<p class='pno'>" . $echo_er . "</p>";
}
} else {
if($err === 0) {
$sql = "INSERT INTO registrace (name, surname, birth, church, phone, mail, phonep, mailp)
VALUES ('$name', '$surname', '$birth', '$church', '$phone', '$mail', '', '')";
$conn->query($sql);
echo "<p class='pyes'> Registration comlete! </p>";
} else {
echo "<p class='pno'>" . $echo_er . "</p>";
}
}
For other variables (name, phone etc ...) I have code above it - no need to put it here. My goal is for PHP to send all the data in the first case and also check all the data.
In the second example, I want to send and check everything except mailp and phonep.
What I tried using the print
variable $more
, so its value is still 1 and does not change.
Maybe it's because the function from JS is from here:
<input type="date" name="birth" id="birth" onchange="adult()">
In both cases, it sends and checks all data (including mailp and phonep).
Does anyone know how to fix this, please?