所以我有这个程序,用户可以在其中设置数据库表。首先,我问他们想要多少个字段。
first.php
<html>
<form name="formCreateFields" method="post" align="center" action="second.php">
<p>Number of fields: <input type ="text" name="fieldsNum"/>
<input type="submit" name="submitFieldsNum" value=" Submit "/></p><br>
</form>
</html>
然后,根据上面的输入,循环这些字段。
second.php
<?php
echo "<form name='formSetupFields' method='post' align='center' action='third.php'>";
for ($z=1; $z<=$_POST['fieldsNum']; $z++) {
echo "<table align='center'>
<tr>
<th rowspan=2> <big> $z </big> </th> <th>Name</th> <th>Type</th> <th>Length</th>
</tr>
<tr>
<td><input type='text' name='fieldName$z'></td>
<td><input type='text' name='fieldType$z'></td>
<td><input type='text' name='fieldLength$z'></td>
</tr>
</table><br><br>";
}
<input type='submit' name='submitFieldSetup'>
</form>";
?>
此后,我遇到了问题。我一直在尝试通过将它们放置在数组中并foreach
用来查看它们来测试获取它们,但似乎什么也做不到。我以为可以使用类似的东西,$_POST['fieldName$z']
但我想我错了。
我只需要了解如何获取第二个文件中的所有输入。有任何想法吗?提前致谢!:)
如果fieldsNum
为数字,则for
在这种情况下应该是正确的,只需将值正确连接即可:
echo "<form name='formSetupFields' method='post' align='center' action='third.php'>";
echo "<table align='center'>";
echo '
<tr>
<th rowspan=2></th> <th>Name</th> <th>Type</th> <th>Length</th>
</tr>';
for ($z = 1; $z <= $_POST['fieldsNum']; $z++) {
echo "
<tr>
<td><input type='text' name='inputs[$z][name]'></td>
<td><input type='text' name='inputs[$z][type]'></td>
<td><input type='text' name='inputs[$z][length]'></td>
</tr>
";
}
echo '</table><br><br>';
echo "<input type='submit' name='submitFieldSetup'>";
echo '</form>';
然后在third.php
;
if(isset($_POST['inputs'])) {
$inputs = $_POST['inputs'];
foreach($inputs as $input) {
echo $input['name'];
echo $input['type'];
echo $input['length'];
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句