我想要创建一个选择页面(通过使用复选框),最后它将显示所有复选框的选择结果。在我的第一页中大约有5种不同类型的复选框(仅包含HTML),用于情感、时间、动作、工具和个性化。
首页: index.php
<div>
<form action="process.php" method="post">
<label>Select your emotions :</label>
<input type="checkbox" name="emotions[]" value="Sadness"> Sadness
<input type="checkbox" name="emotions[]" value="Anxiety"> Anxiety
<input type="checkbox" name="emotions[]" value="Anger"> Anger
<input type="checkbox" name="emotions[]" value="Disgust"> Disgust
<input type="checkbox" name="emotions[]" value="Fear"> Fear
<input type="checkbox" name="emotions[]" value="Surprised"> Surprised
<br>
<label>Select your time to commit :</label>
<input type="checkbox" name="time[]" value="1"> Less than 1 minute
<input type="checkbox" name="time[]" value="1-3"> 1-3 minutes
<input type="checkbox" name="time[]" value="3-5"> 3-5 minutes
<input type="checkbox" name="time[]" value="5-10"> 5-10 minutes
<input type="checkbox" name="time[]" value="10-15"> 10-15 minutes
<input type="checkbox" name="time[]" value="15-30"> 15-30 minutes
<br>
<label>Select how you want to move :</label>
<input type="checkbox" name="movement[]" value="Lying Down"> Lying Down
<input type="checkbox" name="movement[]" value="Sitting"> Sitting
<input type="checkbox" name="movement[]" value="Standing"> Standing
<input type="checkbox" name="movement[]" value="Stretching"> Stretching
<input type="checkbox" name="movement[]" value="Walking"> Walking
<input type="checkbox" name="movement[]" value="Work-out"> Work-out
<br>
<label>Tools around me :</label>
<input type="checkbox" name="tools[]" value="Me"> Me
<input type="checkbox" name="tools[]" value="Pen & Paper"> Pen & Paper
<input type="checkbox" name="tools[]" value="Bottle"> Bottle
<input type="checkbox" name="tools[]" value="Color Pencils"> Color Pencils
<input type="checkbox" name="tools[]" value="Drinks"> Drinks
<input type="checkbox" name="tools[]" value="Snacks"> Snacks
<label>Personalization :</label>
<input type="checkbox" name="personalization[]" value="Favorites"> Favorites
<input type="checkbox" name="personalization[]" value="New"> New
<input type="checkbox" name="personalization[]" value="Completed"> Completed
<input type="checkbox" name="personalization[]" value="Islamic"> Islamic
</div>
<div>
<button type="submit">Submit</button>
</div>第二页: process.php
<?php
$emotions = (isset($_POST['emotions'])) ? $_POST['emotions'] : array(); ?>
<p><strong>Emotions :</strong>
<?php
if (count($emotions) > 0) {
foreach ($emotions as $emotions) {
echo $emotions . ' ';
}
} else {
echo "No emotions has been selected";
}
?>
</p>
<?
$time = (isset($_POST['time'])) ? $_POST['time'] : array(); ?>
<p><strong>Time :</strong>
<?php
if (count($time) > 0) {
foreach ($time as $time) {
echo $time . ' ';
}
} else {
echo "No time has been selected";
}
?>
</p>
<?
$movement = (isset($_POST['movement'])) ? $_POST['movement'] : array(); ?>
<p><strong>Movement :</strong>
<?php
if (count($movement) > 0) {
foreach ($movement as $movement) {
echo $movement . ' ';
}
} else {
echo "No movements has been selected";
}
?>
</p>
<?
$tools = (isset($_POST['tools'])) ? $_POST['tools'] : array(); ?>
<p><strong>Tools :</strong>
<?php
if (count($tools) > 0) {
foreach ($tools as $tools) {
echo $tools . ' ';
}
} else {
echo "No tools has been selected";
}
?>
</p>
<?
$personalization = (isset($_POST['personalization'])) ? $_POST['personalization'] : array(); ?>
<p><strong>Personalization :</strong>
<?php
if (count($personalization) > 0) {
foreach ($personalization as $personalization) {
echo $personalization . ' ';
}
} else {
echo "No personalization has been selected";
}
?>
</p> 发布于 2022-02-09 07:13:33
检查是否在form标记的action属性中输入了正确的路径以到达"process.php“文件
发布于 2022-02-09 07:30:45
回顾你的前瞻。你所做的是:
$array = [1, 2, 3];
foreach($array as $array){
// $array is no more an array, but have the first value of the init array : 1
}就像这样:$array = $array
你必须这样做:
$array = [1, 2, 3];
foreach($array as $ar){
...
// code for $ar
...
}https://stackoverflow.com/questions/70381108
复制相似问题