【发布时间】:2015-09-29 08:53:42
【问题描述】:
<p><?php include 'header.php'; ?></p>
<div align="justify">
<td><form method="post" action="search.php">
Name: <input type="text" name="search" />
<input type="submit" name="submit" value="Search">
</form></td>
<td><form method="post" action="grouprank.php">
Rank: <input type="text" name="groupby" />
<input type="submit" name="submit" value="Group by">
</form></td>
<?php
require ("dbfunction.php");
$con = getDbConnect();
?>
//start here
<form name="form" id="form" action="multiedit.php" method="post">
<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' name = 'checkbox2[]' value='" . $row['crew_id']. "' >" . "</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>
</table>
</form>
</body>
multiedit.php
<?php include 'header.php'; ?>
<div id="container4"><?php
require ("dbfunction.php");
$con = getDbConnect();
$checkbox2 = $_POST['checkbox2'];
if (!mysqli_connect_errno($con)) {
$str =implode($checkbox2);
$queryStr = "SELECT * " .
"FROM crewlist WHERE ($str)";
}
$result = mysqli_query($con, $queryStr);
//if (!$check1_res) {
// printf("Error: %s\n", mysqli_error($con));
// exit();
//}
print_r($_POST);
while ($row = mysqli_fetch_array($result)) {
if (date("Y-m-d") > $row['start_date'] && date("Y-m-d") < $row['end_date']) {
echo "<tr><th>" . $row["crew_name"] . ":</th><br>";
echo " <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><br><br>";
}
}
?>
这就是流程应该如何工作,我检查了几条记录,复选框应该将用户的 id 传递到编辑页面,在那里它应该显示被检查的记录。使用 print_r($_POST) 显示 id 像这样传递到数组中 (Array ( [checkbox2] => Array ( [0] => 378 [1] => 379 ) ) ) 。但是它显示了用户的每条记录。
更新至 2015 年 9 月 30 日下午 3:58 SGT 已解决。到处都有误解。
【问题讨论】:
-
“链接中没有id”什么链接?
-
通常如果要提交表单,应将其链接到用户的ID。例如,multiedit.php?id=363
-
我不确定我是否遵循,您的表单是通过
$_POST而不是$_GET提交的,并且我可以看到您的复选框包含静态文本值,而不是 ID -
是的,这就是我打算前进的方向,但我似乎无法获得正确的代码。
-
.... 什么?你们都准备好在别处分配动态值了,我真的不明白你的问题。