HTML多个具有相同名称/ ID的表单
I'm currently designing a website that reads information from a MySQL database in PHP and prints out a form for each row. This is done using a while loop, so the form is echoed out inside the loop. However, whenever I submit the form, a lot of the values aren't posted because there are forms with the same NAME and ID on the page.
How can I print out one form per item in the database and process this form accordingly? Thanks!
while (*this goes through each row in the database) {
echo "<form name='myForm' id='myForm' method='post' action=''>
<input type='text' name='text1'>
</form>";
}
I want to use a loop to print out a dynamic number of forms.
我目前正在设计一个网站,用PHP读取MySQL数据库中的信息并打印出每行的表格 。 这是使用while循环完成的,因此表单在循环内回显。 但是,每当我提交表单时,都会发布很多值,因为页面上有相同名称和ID的表单。 p>
如何打印出一个表单 数据库中的项目并相应处理此表单? 谢谢! p>
while(*这会遍历数据库中的每一行){
echo“&lt; form name ='myForm'id ='myForm'method ='post 'action =''&gt;
&lt; input type ='text'name ='text1'&gt;
&lt; / form&gt;“;
}
code> pre>
我想使用循环打印出动态数量的表单。 p>
div>
Just change the form name and id with each iteration by adding a counter to your loop.
$i = 0;
while (*this goes through each row in the database) {
echo "<form name='myForm" . $i . "' id='myForm" . $i . "' method='post' action=''>
<input type='text' name='text1'>
</form>";
$i++;
}
Or possibly even better is if you have some sort of unique database id for each record, use that id value instead of a counter.