我在PHP代码中遇到问题,我构建了一个每周学者日历作为表示“小时”的五列表格,在第一列中我设置了日历的“天”。我使用了7个类,我的代码已经工作了,它显示了我喜欢的日期和时间但是我有插入日期的问题,我使用foreach循环来获取日期并将两个复选框和一个标签复制到四列中“小时” ;所以当我插入数据;我进入了MySQL平台,我在本周的所有七天都插入了。我不知道我是否解释得很好。代码有点复杂而且很长,我只会加入我认为是代码中问题根源的foreach代码。
<tbody action="week.php">
<tr>
<th>
<?php foreach($currentWeek->days() as $day ): ?>
<?php echo $day->name() ?> <?php echo $day->int()?> <?php echo $firstDay->month()->name()?>
</th>
<td>
<form method="post">
<input type="checkbox" name="abs" value="Absence">Absence<input type="checkbox" name="abs" value="delay">delay
<input type="text" name="justify" placeholder="Justify the absence" minlength="2" required autofocus></th>
<button type="submit" name="enreg1">Validate</button> </form>
<?php
echo $day;
?>
<?php
if(isset($_REQUEST['enreg1'])){
if($day == NOW())
{$sql="INSERT INTO absence(cne,date,seance1,justif1)
VALUES('1234','".$day."','".$_POST["abs"]."','".$_POST["justify"]."');";
$res=$conn->prepare($sql);
$res->execute();
$res->closeCursor();}
}
?>
</td>
<td>
<form method="post">
<input type="checkbox" name="abs" value="Absence">Absence<input type="checkbox" name="abs" value="delay">delay
<input type="text" name="justify" placeholder="Justify the absence" minlength="2" required autofocus></th>
<button type="submit" name="enreg2">Validate</button> </form>
<?php echo $day;
?></td>
<td>
<form method="post">
<input type="checkbox" name="abs" value="Absence">Absence<input type="checkbox" name="abs" value="delay">delay
<input type="text" name="justify" placeholder="Justify the absence" minlength="2" required autofocus></th>
<button type="submit" name="enreg3">Validate</button> </form>
<?php
echo $day; ?></td>
<td>
<form method="post">
<input type="checkbox" name="abs" value="Absence">Absence<input type="checkbox" name="abs" value="delay">delay
<input type="text" name="justify" placeholder="Justify the absence" minlength="2" required autofocus></th>
<button type="submit" name="enreg4">Validate</button> </form>
<?php
echo $day; ?></td>
</tr>
<tr>
<th>
<?php endforeach ?>
</th>
</tr>