我有一个PHP脚本,可以在我拥有的页面上生成一些表单。我还在表单中有一个表和提交按钮,一切正常,数据按预期发送到下一页。现在在下一页我有一个PHP代码,它读取$_POST
变量。这是我的代码:
echo "<form name=\"myForm\" id=\"myForm\" method=\"post\" action=\"\">";
echo "<table>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Name</th>";
echo "<th>Group</th>";
echo "</tr>";
while($row = mysql_fetch_array($qryRes))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td><input name=\"aName" . $row['id'] . "\" id=\"aName" . $row['id'] . "\" type=\"text\" value=\"" . $row['aName'] . "\" /></td>";
echo "<td><select name=\"gID" . $row['id'] . "\">";
while($gRow = mysql_fetch_array($grpsQry))
{
if($gRow['id'] == $row['groupID'])
echo "<option id=\"" . $gRow['id'] . "\" selected=\"selected\">" . $gRow['gName'] . "</option>";
else
echo "<option id=\"" . $gRow['id'] . "\">" . $gRow['gName'] . "</option>";
}
echo "</select></td>";
echo "</tr>";
mysql_data_seek( $grpsQry, 0 );
}
echo "</table>";
echo "<input type=\"submit\" name=\"submitForm\" value=\"Save\" />";
echo "</form>";
然后我的PHP代码来阅读$_POST
:
if(isset($_POST['submitForm']))
{
print_r($_POST);
foreach($_POST as $x)
echo $x . "<br />";
}
一切正常,除了我只需要读取foreach
循环中的文本字段,因为我将对它们生成查询,并将比较我将具有的值{{1 }} ..
正如你所知,List
被命名为textfield
,然后是用户的ID。我只需要读这个。但我会用它来生成一个查询,然后将其与List aName
的值进行比较。
答案 0 :(得分:5)
试试这个:
foreach($_POST as $key => $value){
if(substr($key,0,5) == 'aName')
echo $value . "<br />";
}