【发布时间】:2014-10-17 13:35:57
【问题描述】:
我正在使用 PHP 创建一个 HTML 表格,其中表格中的每一行都包含输入类型为“文本”的单元格。在行的末尾有一个提交按钮,它将从表格单元格的输入字段中读取数据。
我使用 $_GET 方法编写的代码在单击提交按钮后读取我的 url 的操作,但此操作的 PHP 代码无法正确确定表中输入字段的数据是否为空.
PHP 代码:
$time_cell_row = 1;
// <input name="userid" type="hidden" id="userid" value="<? echo $rows['userid'];
while($tasks_row = $tasks_result->fetch_array()) {
$time_cell_column = 1;
echo "<form name='timesubmit" . $time_cell_row . "' action='enter_time.php?action=timesubmit" .$time_cell_row . "' method='post'>";
echo "<tr>
<td>" . $tasks_row['taskname'] . "</td>
<td><input name=taskdaycell" . $time_cell_row . $time_cell_column . " type=text></input></td>";
$time_cell_column++;
echo "<td><input name=taskdaycell" . $time_cell_row . $time_cell_column . " type=text></input></td>";
$time_cell_column++;
echo "<td><input name=taskdaycell" . $time_cell_row . $time_cell_column . " type=text></input></td>";
$time_cell_column++;
echo "<td><input name=taskdaycell" . $time_cell_row . $time_cell_column . " type=text></input></td>";
$time_cell_column++;
echo " <td><input name=taskdaycell" . $time_cell_row . $time_cell_column . " type=text></input></td>";
$time_cell_column++;
echo "<td><input name=taskdaycell" . $time_cell_row . $time_cell_column . " type=text></input></td>";
$time_cell_column++;
echo "<td><input name=taskdaycell" . $time_cell_row . $time_cell_column . " type=text></input></td>";
echo "<td><input name=submit_time" . $time_cell_row . $time_cell_column . " type=submit></input></td>";
echo "</form></tr>";
$time_cell_row++;
}
if (isset($_GET['action'])) {
switch (strtolower($_GET['action'])) {
case 'timesubmit1':
if ( !isset($_POST['taskdaycell11']) || !isset($_POST['taskdaycell12']) || !isset($_POST['taskdaycell13'])
|| !isset($_POST['taskdaycell14']) || !isset($_POST['taskdaycell15']) || !isset($_POST['taskdaycell16'])
|| !isset($_POST['taskdaycell17'])) {
echo "<b>Please do not leave any of the times blank</b><br>";
}
else {
echo "Your times have been entered.";
}
break;
}
}
现在,如果我将表格单元格留空并单击“提交”按钮,即使输入字段为空白,输出也会始终显示“您的时间已输入”。
【问题讨论】:
-
除非我误解了您的代码,否则您的 switch 语句正在寻找“timesubmit1”,而您的表单将操作提交为简单的“timesubmit”
-
我实际上有 $time_cell_row = 1 并且我有寻找“timesubmit1”的动作。当我点击提交按钮时,网址实际上显示“action=timesubmit1”
-
哦,好吧。我是误解了你的代码。
-
@wavemode 没关系,我有时也会误解代码。感谢您的帮助!