无法从复选框中获取值并在另一个php文件上使用
我创建了一个复选框,允许用户同时进行多个编辑,但我不知道如何将“提交”按钮链接到复选框,然后在下一页中显示这些选定的选项 这是复选框页面无法从复选框中获取值并在另一个php文件上使用,php,mysql,Php,Mysql,我创建了一个复选框,允许用户同时进行多个编辑,但我不知道如何将“提交”按钮链接到复选框,然后在下一页中显示这些选定的选项 这是复选框页面 <?php require ("dbfunction.php"); $con = getDbConnect(); ?> <td> <td> <input type="che
<?php
require ("dbfunction.php");
$con = getDbConnect();
?>
<td>
<td>
<input type="checkbox" id ='checkbox1' name="checkbox1" onclick="load();" value="Bike">Include previous service terms</td>
</div>
<div id="show">
</div>
<p><table>
<tr>
<th>Tick</th>
<th>Name</th>
<th>Rank</th>
<th>Start Date</th>
<th>End Date</th>
<th>Watchkeeping</th>
<th>Active</th>
</tr> <!-- database -->
<tr>
<?php
if (!mysqli_connect_errno($con)) {
$queryStr = "SELECT * " .
"FROM crewlist";
}
$result = mysqli_query($con, $queryStr);
while ($row = mysqli_fetch_array($result)) {
if (date("Y-m-d") > $row['start_date'] && date("Y-m-d") < $row['end_date']) {
echo "<tr><th>" . "<input type = \"checkbox\" id ='checkbox2' value=\"checkbox2\" >" . "</th>";
echo "<th>" . "<a href=\"viewcrew.php?id=" . $row['crew_id'] . "\">" . $row["crew_name"] . "</a>";
echo "<th>" . $row["crew_rank"] . "</th>";
echo "<th>" . $row["start_date"] . "</th>";
echo "<th>" . $row["end_date"] . "</th>";
echo "<th>" . $row["watchkeeping"] . "</th>";
echo "<th>" . $row["active"] . "</th>";
} else {
}
}
?>
</tr>
<input type="submit" value="Submit" ></td
</tr>
包括以前的服务条款
打上钩
名称
等级
开始日期
结束日期
值班
活跃的
错误
错误
)
echo”“。"" . "";
在此行中,您没有指定名称属性。应该是这样的
echo "<tr><th>" . "<input type = \"checkbox\" name ='checkbox2[]' id ='checkbox2' value=\"checkbox2\" >" . "</th>";
echo”“。"" . "";
因为它有多个值,所以我们在名称中使用[]数组参数
您可以从下一页获取它,如
假设方法是post-$\u post['checkbox2'],它将返回所选的复选框数组。HTML错误除外,您需要使用一个表单标记,它将把您发送到page2.php
。我不能检查你的其他工作,它都有点混乱
<?php
require ("dbfunction.php");
$con = getDbConnect();
?>
<form name="whatever" id="whatever" action="page2.php" method="post">
<table>
<tr>
<td colspan="6"> </td>
<td>
<input type="checkbox" id ='checkbox1' name="checkbox1" onclick="load();" value="Bike">
Include previous service terms
<div id="show"></div>
</td>
</tr>
<tr>
<th>Tick</th>
<th>Name</th>
<th>Rank</th>
<th>Start Date</th>
<th>End Date</th>
<th>Watchkeeping</th>
<th>Active</th>
</tr>
<?php
if (!mysqli_connect_errno($con)) {
$queryStr = "SELECT * FROM crewlist";
$result = mysqli_query($con, $queryStr);
$i = 0;
while ($row = mysqli_fetch_array($result)) {
if (date("Y-m-d") > $row['start_date'] && date("Y-m-d") < $row['end_date']) {
?>
<tr>
<td>
<input type = "checkbox" id ="checkbox<?php echo $i; ?>" name="checkbox[]" value="checkbox<?php echo $i; ?>" />
</td>
<td>
<a href="viewcrew.php?id=<?php echo $row['crew_id']; ?>"><?php echo $row["crew_name"]; ?></a>
</td>
<td>
<?php echo $row["crew_rank"]; ?>
</td>
<td>
<?php echo $row["start_date"]; ?>
</td>
<td>
<?php echo $row["end_date"]; ?>
</td>
<td>
<?php echo $row["watchkeeping"]; ?>
</td>
<td>
<?php echo $row["active"]; ?>
</td>
</tr>
<?php
$i++;
}
}
}
?>
<tr>
<td colspan="7">
<input type="submit" name="submit" value="Submit" >
</td>
</tr>
</table>
</form>
您需要一个表单标记,其中包含一个可转到第二页的操作。
echo "<tr><th>" . "<input type = \"checkbox\" name ='checkbox2[]' id ='checkbox2' value=\"checkbox2\" >" . "</th>";
<?php
require ("dbfunction.php");
$con = getDbConnect();
?>
<form name="whatever" id="whatever" action="page2.php" method="post">
<table>
<tr>
<td colspan="6"> </td>
<td>
<input type="checkbox" id ='checkbox1' name="checkbox1" onclick="load();" value="Bike">
Include previous service terms
<div id="show"></div>
</td>
</tr>
<tr>
<th>Tick</th>
<th>Name</th>
<th>Rank</th>
<th>Start Date</th>
<th>End Date</th>
<th>Watchkeeping</th>
<th>Active</th>
</tr>
<?php
if (!mysqli_connect_errno($con)) {
$queryStr = "SELECT * FROM crewlist";
$result = mysqli_query($con, $queryStr);
$i = 0;
while ($row = mysqli_fetch_array($result)) {
if (date("Y-m-d") > $row['start_date'] && date("Y-m-d") < $row['end_date']) {
?>
<tr>
<td>
<input type = "checkbox" id ="checkbox<?php echo $i; ?>" name="checkbox[]" value="checkbox<?php echo $i; ?>" />
</td>
<td>
<a href="viewcrew.php?id=<?php echo $row['crew_id']; ?>"><?php echo $row["crew_name"]; ?></a>
</td>
<td>
<?php echo $row["crew_rank"]; ?>
</td>
<td>
<?php echo $row["start_date"]; ?>
</td>
<td>
<?php echo $row["end_date"]; ?>
</td>
<td>
<?php echo $row["watchkeeping"]; ?>
</td>
<td>
<?php echo $row["active"]; ?>
</td>
</tr>
<?php
$i++;
}
}
}
?>
<tr>
<td colspan="7">
<input type="submit" name="submit" value="Submit" >
</td>
</tr>
</table>
</form>
<?php
include('header.php');
require("dbfunction.php");
$con = getDbConnect();
print_r($_POST);
?>
<div id="container4">
<table>
<?php
if(!mysqli_connect_errno($con)) {
$queryStr = "SELECT * FROM crewlist";
$result = mysqli_query($con, $queryStr);
while($row = mysqli_fetch_array($result)) {
if((date("Y-m-d") > $row['start_date']) && (date("Y-m-d") < $row['end_date'])) {
?>
<tr>
<th colspan="2"><?php echo $row["crew_name"]; ?>:</th>
</tr>
<tr>
<td>Shift 1:</td>
<td>
<input type="time" name="start_hour" value="start_hour" id="start_hour" step="1800" required /> to
<input type="time" name="end_hour" value="end_hour" id="end_hour" step="1800" required />
</td>
</tr>
<tr>
<td>Shift 2:</td>
<td>
<input type="time" name="start_hour2" value="start_hour2" id="start_hour2" step="1800" required /> to
<input type="time" name="end_hour2" value="end_hour2" id="end_hour2" step="1800" required />
</td>
</tr>
<?php }
}
?>
<tr>
<td><input type="submit" value="Submit" ></td>
</tr>
<?php }
?>
</table>
</div>