gpt4 book ai didi

php - 如何检查提交了哪个按钮

转载 作者:可可西里 更新时间:2023-11-01 07:35:02 25 4
gpt4 key购买 nike

我有一个表格,像这样:

echo '<table align=center border=1>';
echo '<form method="post">';
echo '<tr>';
echo '<th>Lista Echipamente</th>';
echo '<th>Actiune</th>';
echo '</tr>';
while($row=mysql_fetch_array($sql)){
echo '<tr>';
echo '<td><input class="search-logi" id="tip" type="text" name="tip" value="'.$row['tip'].'"></td>';
echo '<td><input type=submit name=modifica value=Modifica></td>';
echo '</tr>';
}
echo '</form>';
echo '</table>';

因为循环,这个表单会有多行。对于每个输入,将是一个按钮。假设我想在第二个输入中添加一个值,然后我将提交它(显然也是第二个按钮)。问题来了,在我的代码中我只有一个按钮,但用户看到的次数与循环次数一样多。如何检查提交了哪个按钮?

最佳答案

或者,您可以使用 <button>用于此目的的标签:

echo '<form method="post">'; // form tags are outside to be valid!!!
echo '<table align=center border=1>';
echo '<tr>';
echo '<th>Lista Echipamente</th>';
echo '<th>Actiune</th>';
echo '</tr>';

while($row = mysql_fetch_assoc($sql)){
echo '<tr>';
echo '<td><input class="search-logi" type="text" name="tip['.$row['id'].']" value="'.$row['tip'].'"></td>';
echo '<td><button type="submit" name="modifica" value="'.$row['id'].'">Modifica</button</td>';
echo '</tr>';
}

echo '</table>';
echo '</form>';

然后在处理表单上:

$modifica = $_POST['modifica']; // shoud return the index num
$tip = $_POST['tip'][$modifica]; // select which textbox

关于php - 如何检查提交了哪个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26341621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com