1

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>";

I am a PHP newbie, I want those "edit" and "delete" buttons to send a POST request to a options.php page, but with this code when I hit a button nothing happens. How can I fix this error?

The second form option is ok for now

AJJ
  • 7,365
  • 7
  • 31
  • 34
Jay Sithiporn
  • 91
  • 5
  • 14
  • Welcome to Stack Overflow! Please, don't use `mysql_*` functions for new code. They are no longer maintained and the community has begun the [deprecation process](http://goo.gl/KJveJ). See the [**red box**](http://goo.gl/GPmFd)? Instead you should learn about [prepared statements](http://goo.gl/vn8zQ) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you can't decide, [this article](http://goo.gl/3gqF9) will help to choose. If you care to learn, [here is good PDO tutorial](http://goo.gl/vFWnC). – Madara's Ghost Jun 29 '12 at 06:43
  • you need to define `onclick` action with the buttons. – hjpotter92 Jun 29 '12 at 06:43
  • is your `options.php` in the same directory with this html form? – ianace Jun 29 '12 at 06:58

5 Answers5

1
  1. Open and close the <form> tag outside the while loop
  2. Use <input type='submit'>. Refer this link to see how can you use two submit buttons in one form
  3. And finally as Truth mentioned above, use PDO / MySQLi
Community
  • 1
  • 1
skos
  • 4,102
  • 8
  • 36
  • 59
0

You must add some action to the button, i.e. <input type='button' name='edit' value='edit' onClick='edit()'>. When you click it, a javascript function edit() wil be called. It should have some AJAX request to your php page, POST or GET. You can use jQuery for that.

maialithar
  • 3,065
  • 5
  • 27
  • 44
0

You either need to add a javascript function to the button's onclick that fires a form submission, or change the button type from "button" to "submit" in order for it to post the page.

Ekster
  • 353
  • 1
  • 4
0

Change type='button' to type='submit'.

You should close input tags simply by adding a whitespace and a slash to the end. Like this:

<input type='text' name='username' />

I don't know if you want to have multiple forms or just 1. If you want 1 form, than put <form></form> tags outside the while loop.

j0k
  • 22,600
  • 28
  • 79
  • 90
Pixel
  • 104
  • 1
  • 10
-2
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>";

Try something like this.

Piotr Olaszewski
  • 6,017
  • 5
  • 38
  • 65