我在输入变量值时遇到了一些问题。
为了便于理解。我在mysql数据库中有一些客户信息,我在表中用php输出。我现在正在研究删除选项。
它必须像这样工作,当我点击按钮,它抓取行ID,然后我发送行ID到delete.php,它被删除。
但现在我有问题,因为例如,如果我有10行(10个不同的客户端),每次我从第一行得到ID,
请检查下面我的代码,并试图帮助我找出它的错误,所以为什么我没有得到正确的行ID的形式。
<?php
while($row = mysql_fetch_array($result))
{
echo "
<table align='center' width='962px' style='color:#000; font-family:Tahoma;'>
<tr>
<td width='5%' height='35'><center><span class='text3'>" . $row['id'] . "</span></center></td>
<td width='22%' height='35'><center><span class='text3'>" . $row['imeinpriimek'] . "</span></center></td>
<td width='18%' height='35'><center><span class='text3'>" . $row['datuminkrajrd'] . "</span></center></td>
<td width='25%' height='35'><center><span class='text3'>" . $row['datumvnosa'] . "</span></center></td>
<td width='30%' height='35'>
<form action='delete.php' method='post' id='form'>
<button type='button' style='border: 0; background: #fff;' onclick='"popup('Želiš izbrisati spodaj navedenega klienta?<br><br> <b>" . $row['imeinpriimek'] . "</b>')'"><img src='images/delete.png' title='Izbriši'><input type='text' name='id' value='" . $row['id'] . "' /</button>
<div id='dialog-box'>
<div class='dialog-content'>
<div id='dialog-message'></div>
<button type='submit' onclick='"$('#form').submit()'" style='border:1px solid #125e94; border-radius: 3px; -moz-border-radius: 3px; font-size:12px; width: 30px; height: 25px; text-align:center; color: #e6e4e2; background: #0397ff;'>Da</button>
<button style='border:1px solid #125e94; border-radius: 3px; -moz-border-radius: 3px; font-size:12px; width: 30px; height: 25px; text-align:center; color: #e6e4e2; background: #0397ff;'>Ne</button>
</form>
</div>
</div>
</td>
</tr>
</table>
";
}
mysql_close($con);
?>
谢谢
所有表单都有相同的id,但它必须是唯一的。变化:
<form action='delete.php' method='post' id='form'>
<form action='delete.php' method='post' class='form'>
和
<button type='submit' onclick='"$('#form').submit()'">Da</button>
<!-- No need to use onclick, since this is type="submit" button -->
<button type='submit'>Da</button>
我认为你需要给每个表单一个唯一的id。也许改一下
<form action='delete.php' method='post' id='form'>
<form action='delete.php' method='post' id='form". $row['id']."'>
,你需要改变行提交按钮引用的形式也:
<button type='submit' onclick='"$('#form".$row['id']."').submit()'" style='border:1px solid #125e94; border-radius: 3px; -moz-border-radius: 3px; font-size:12px; width: 30px; height: 25px; text-align:center; color: #e6e4e2; background: #0397ff;'>Da</button>
但正如dfsq在他的回答中指出的那样,在submit
类型按钮中实际上不需要onclick
部分
这取决于你如何处理表单数据在服务器端,当你得到它。请注意,您也没有为其他<div>
(如dialog-box
和dialog-message
)提供唯一的id。这将导致无效的html。但是,我不确定这是否会导致问题。