220061
Well-Known Coder
Hello I'm kinda stuck here and I don't know what to do. I have this code where I want to (based on the choice that the user made) put the timestamp into my table
its goes like this if you choose option 1 then insert NULL into both the columns inlever_datum and uitleen_datum
if you choose option 0 then insert the current timestamp in Y-m-d into uitleen_datum and for inlever_datum put a day 7 days later (so current time + 7 days)
now I have this code
what am I doing wrong here ???
its goes like this if you choose option 1 then insert NULL into both the columns inlever_datum and uitleen_datum
if you choose option 0 then insert the current timestamp in Y-m-d into uitleen_datum and for inlever_datum put a day 7 days later (so current time + 7 days)
now I have this code
PHP:
<div class="container">
<div class="form">
<h2>Apparaten toevoegen</h2>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
<!--naam van het apparaat-->
<label for="naam">Naam </label><br>
<input type="text" name="naam" id="naam" required="required"> <br><br/><br/>
<!--beschrijving van het product -->
<label for="beschrijving">Beschrijving </label>
<input type="text" name="beschrijving" id="beschrijving" required="required">
<br><br/><br/>
<!--beschikbaar dropdown-->
<!--this is where the option part is -->
<label for="beschikbaar">Beschikbaar </label><br>
<select name="beschikbaar" class="beschikbaar" value="true" required="required"'>
<option hidden>--Select option--</option>
<option value="1">Beschikbaar</option>
<option value="0">Uitgeleend</option>
</select>
<!--submit button-->
<br><br><input type="submit" value="Toevoegen" name="submit">
<?php
//link voor het stoppen van empty values
//dit zou alles naar de database moeten sturen als je op de knop drukt
// informatie naar de DB sturen
if (isset($_POST["submit"])) {
date_default_timezone_set("America/New_York");
switch($_POST['beschikbaar']){
case "1":
$date = date("Y/m/d"); //works
var_dump($date);
//empty table
$stmt = $conn->prepare("INSERT INTO apparatuur( inlever_datum, uitleen_datum ) VALUES ('%s', NULL)");
var_dump($stmt); // gives false??
$stmt->bind_param("i", $inlever_datum);
$stmt->execute();
break;
case "0":
$date = date("Y/m/d");
var_dump($date);
// + 7 dagen
$stmt = $conn->prepare("INSERT INTO apparatuur( uitleen_datum ) VALUES ('%s', CURDATE())");
var_dump($stmt);
$stmt->bind_param("i", $uitleen_datum);
$stmt->execute();
break;
default:
echo "<p>U heeft geen optie gekozen</p>";
}
echo $stmt;
//dit nog veranderen voor als optie 0 word aangeklikt
//prepared statement
$stmt = $conn->prepare("INSERT INTO apparatuur (naam, beschrijving,beschikbaar)
VALUES (?,?,?)");
$stmt->bind_param("ssi", $naam, $beschrijving,$beschikbaar);
$stmt->execute();
function_alert("Apparaat is toegevoegd");
$conn->close();
}
?>
</form>
</div>
</div>
</body>
<footer>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
</footer>
</html>
what am I doing wrong here ???