I have this error. I already manage to insert my data in database. but the problem is my date in 0000-00-00. What is the error? I tried to change the format but also the same. I’ll attach my code.
error
php code.
<?php
include ('connect.php');
$book = filter_input(INPUT_POST,'check',FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
if(isset($_POST['submit']))
{
$c_id = 4;
$date_today = $_POST['frmDateReg'];
$service_date = filter_input(INPUT_POST,'pickup_date',FILTER_SANITIZE_STRING);
$masa = filter_input(INPUT_POST,'pagi',FILTER_SANITIZE_STRING);
$datetoday = date('Y-m-d',strtotime($date_today));
$sql2 = mysqli_query($conn,"INSERT INTO booking(bookDate,serviceDate,bookTime,cust_fk) VALUES ($datetoday,$service_date,$masa,$c_id)" );
?>
html code
<input type="date" class="textbox" id="pick_date" name="pickup_date" /></p>
<input type="text" name="frmDateReg" id="frmDate" value="<?php echo date('d/m/Y'); ?>" readonly="">
<script type="text/javascript">
let dateInput = document.getElementById('pick_date');
const cur_date = new Date();
cur_date.setDate(cur_date.getDate() + 3);
var dateStr = cur_date.toISOString().split("T")[0];;
dateInput.setAttribute('min', dateStr);
</script>
2
Answers
i already found my answer for my problem.
the error is in this line. i forget to put ' ' on the $date and $service_date. lol
If you need to save NULL if the variable is not required or empty, you can try below codes.