再次编辑:新修订的版本
所以我已经纠正了表格中缺少标签,我已经在我的表格中添加了id,我为每个表单添加了一个隐藏字段,其值与表单ID相同(如建议的那样)
我试图修改我的原始if ifset以包含表单id,但那就是我有点不知所措。
如上所述,这是页面创建的HTML:
<br><table border=1><tr><th>customer</th><th>product</th><th>employee</th><th>return_date</th><th>complete</th></tr><br><tr><td>marne1</td><td>basketball</td><td>user</td><td>01-10-12</td><td> <FORM id="1" method ="post" action ="g.php">
<input type='hidden' name='x' value='1'>
<Input type = 'Radio' Name ='ir' value= '47'> 47 <input type="submit" name="return"/>
</FORM>
</td></tr><br><tr><td>marne1</td><td>basketball</td><td>user</td><td>01-10-12</td><td> <FORM id="2" method ="post" action ="g.php">
<input type='hidden' name='x' value='2'>
<Input type = 'Radio' Name ='ir' value= '48'> 48 <input type="submit" name="return"/>
</FORM>
</td></tr><br><tr><td>marne1</td><td>basketball</td><td>user</td><td>02-10-12</td><td> <FORM id="3" method ="post" action ="g.php">
<input type='hidden' name='x' value='3'>
<Input type = 'Radio' Name ='ir' value= '49'> 49 <input type="submit" name="return"/>
</FORM>
</td></tr><br><tr><td>marne1</td><td>basketball</td><td>user</td><td>29-09-12</td><td> <FORM id="4" method ="post" action ="g.php">
<input type='hidden' name='x' value='4'>
<Input type = 'Radio' Name ='ir' value= '50'> 50 <input type="submit" name="return"/>
</FORM>
</td></tr><br><tr><td>marne1</td><td>basketball</td><td>user</td><td>01-10-12</td><td> <FORM id="5" method ="post" action ="g.php">
<input type='hidden' name='x' value='5'>
<Input type = 'Radio' Name ='ir' value= '51'> 51 <input type="submit" name="return"/>
</FORM>
</td></tr><br><tr><td>marne1</td><td>basketball</td><td>user</td><td>01-10-12</td><td> <FORM id="6" method ="post" action ="g.php">
<input type='hidden' name='x' value='6'>
<Input type = 'Radio' Name ='ir' value= '52'> 52 <input type="submit" name="return"/>
</FORM>
</td></tr><br><tr><td>marne1</td><td>basketball</td><td>user</td><td>02-10-12</td><td> <FORM id="7" method ="post" action ="g.php">
<input type='hidden' name='x' value='7'>
<Input type = 'Radio' Name ='ir' value= '60'> 60 <input type="submit" name="return"/>
</FORM>
</td></tr><br><tr><td>marne1</td><td>basketball</td><td>user</td><td>02-10-12</td><td> <FORM id="8" method ="post" action ="g.php">
<input type='hidden' name='x' value='8'>
<Input type = 'Radio' Name ='ir' value= '61'> 61 <input type="submit" name="return"/>
</FORM>
</td></tr><br></table>
<fieldset>
<legend>???</legend>
<form action="z.php" method="post">
Customer Name: <input type="text" name="ir" /> <br><br>
<input type="submit" name="return"/>
</form>
这是创建此HTML的PHP页面(我尝试过的表单id测试):
<?php
$db_host = "localhost";
$db_username = "root";
$db_pass = "usbw";
$db_name = "test";
mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database");
$result = mysql_query("SELECT * FROM rental WHERE customer = '$_POST[customer]' AND complete = '0' ") or die (mysql_error());
?>
<?php
echo '<br>';
echo '<table border=1>';
echo '<tr><th>customer</th><th>product</th><th>employee</th><th>return_date</th><th>complete</th></tr>';
echo "<br>";
$x=1;
while($row=mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>';
echo $row ['customer'];
echo '</td><td>' ;
echo $row ['product'];
echo '</td><td>';
echo $row ['employee'];
echo '</td><td>';
echo $row ['return_date'];
echo '</td><td>';
$cur_return = $row ['rental_id'];
?>
<FORM id="<?php echo $x; ?>" method ="post" action ="g.php">
<input type='hidden' name='x' value='<?php echo $x; ?>'>
<Input type = 'Radio' Name ='ir' value= '<?php echo $cur_return ?>'> <?php echo $cur_return ?>
<input type="submit" name="return"/>
</FORM>
<?php
echo '</td></tr>';
echo '<br>';
$x++;
}
echo '</table>';
?>
<fieldset>
<legend>???</legend>
<form action="z.php" method="post">
Customer Name: <input type="text" name="ir" /> <br><br>
<input type="submit" name="return"/>
</form>
<?php
if (isset($_POST['return']))
{
if ($_POST['x']==1)
{
mysql_query("UPDATE rental SET complete = '1' WHERE rental_id = '$_POST[ir]'") or die (mysql_error());
}
}
?>
我真的非常感谢你们所建议的所有帮助,并且抱歉让我把它排序了:)
富
答案 0 :(得分:2)
在这种情况下,只需将开始表单标记移动到while循环内部的最开头,然后将提交按钮和结束表单标记移动到while循环的底部。它将生成每个表单并仍然保持表的结构。但是你不能只有一个表单提交自己的某些部分,这违反了基本的HTML原则。
我强烈建议在每张表单上打一个ID,以供将来参考和更新。
祝你好运。答案 1 :(得分:1)
您可以使用javascript执行此操作,但不能使用php执行此操作。但它无缘无故地过于复杂。制作不同的表单并将它们分配给不同的ID。您可以使用相同的方法=“post”和相同的action =“g.php”。要在g.php上有所不同,只需将其放在每种形式中:
<input type='hidden' name='x' value='1'>
然后
<input type='hidden' name='x' value='2'>
如果$ _POST ['x'] == 1
,那就简单了另外,请确保保护g.php,这对于处理表单的文件来说是一个非常不安全的名称。