我想创建一个用户可以填充值并提交到数据库的表。表的每一行应保存为表中的单个行。表格示例如下所示。
First | Last | Phone
Steve | Jones | 1234
Jason | Smith | 4567
Mark | Black | 6789
Submit
我将表格创建为表单并使用POST提交。如何仅使用1个提交按钮将每行作为单独的行提交到我的数据库?
答案 0 :(得分:1)
<TextView
android:id="@+id/tv_hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColorHighlight="@color/light_blue"
android:textIsSelectable="true"/>
<强> submitPage.php 强>
<form method='POST' action='submitPage.php'>
<table>
<tr>
<td><input name='first[]'></td>
<td><input name='last[]'></td>
<td><input name='phone[]'></td>
</tr>
<tr>
<td><input name='first[]'></td>
<td><input name='last[]'></td>
<td><input name='phone[]'></td>
</tr>
.
.
</table>
<input type='submit' value='submit details'>
</form>
答案 1 :(得分:0)
<input ... name="contact[1][first]">
<input ... name="contact[1][last]">
<input ... name="contact[1][phone]">
...
<input ... name="contact[2][first]">
<input ... name="contact[2][last]">
<input ... name="contact[2][phone]">
另请查看this question。
P.S。你需要谷歌更好。
答案 2 :(得分:0)
<form>
<fieldset>
<input name="first[]" type="text"/>
....
对您来说可能很有用,将字段名称作为数组允许您迭代它们,例如:
<?php
$firsts = $_POST["first"];
$lasts = $_POST["lasts"];
$num = $_POST["numbers"];
if(count($firsts) == count($lasts) == count($num) {
for($i = 0; $i < count($firsts); $i++) {
$toSubmit = [$firsts[$i], $lasts[$i], $num[$i]];
// put that into your SQL inserts w/e.
}
}
?>