Mycode
$show=mysql_query("SELECT * FROM room_group_options");
while ($array = mysql_fetch_array($show))
{
$op_id = $array['op_id'];
$group = $array['group'];
echo "<form action = 'options.php' method = 'post'>";
echo "$op_id <input type='hidden' name='op_id' value='$op_id'>";
echo "<input type = 'text' name = 'group' value = '$group'>";
echo "<input type='button' name='edit' value='edit'>";
echo "<input type='button' name='del' value='delete'>";
echo "</form><br>";
}
echo "<form action = 'options.php' method = 'post'>
<input type = 'text' name = 'group'><br>
<input type = 'submit' name = 'addgroup'></form>";
我是PHP新手,我希望那些"编辑"和"删除"按钮将POST请求发送到选项.php页面,但是当我点击按钮时使用此代码没有任何反应。如何修复此错误?
第二个表单选项现在可以
- 在 while 循环之外打开和关闭
<form>
标记 - 使用
<input type='submit'>
.请参阅此链接,了解如何在一个表单中使用两个提交按钮 - 最后,正如上面提到的真相,使用PDO/MySQLi
将type='button'
更改为type='submit'
。
您应该通过在末尾添加空格和斜杠来关闭输入标签。喜欢这个:
<input type='text' name='username' />
我不知道你是想拥有多种形式还是只有 1 种形式。如果你想要 1 个表单,那么<form></form>
标签放在 while 循环之外。
您必须向按钮添加一些操作,即 <input type='button' name='edit' value='edit' onClick='edit()'>
.当您单击它时,edit()
调用一个 JavaScript 函数。它应该对您的 php 页面、POST
或GET
有一些AJAX
请求。您可以使用jQuery
。
您需要将 javascript 函数添加到按钮的 onclick 中,以触发表单提交,或者将按钮类型从"按钮"更改为"提交",以便它发布页面。
echo "<form action = 'options.php' method = 'post'>";
$show=mysql_query("SELECT * FROM room_group_options");
while ($array = mysql_fetch_array($show))
{
$op_id = $array['op_id'];
$group = $array['group'];
echo "$op_id <input type='hidden' name='op_id' value='$op_id'>";
echo "<input type = 'text' name = 'group' value = '$group'>";
echo "<input type='button' name='edit' value='edit'>";
echo "<input type='button' name='del' value='delete'>";
}
echo "</form><br>";
echo "<form action = 'options.php' method = 'post'>
<input type = 'text' name = 'group'><br>
<input type = 'submit' name = 'addgroup'></form>";
尝试这样的事情。