1

I have a few Radio Buttons which shell send their value in the post method, when the submit button is clicked. I am pretty sure it is easy, but for any reason it does not work. It sends the calue of the submit button instead. Please help me. This is my code for now(this code is inside a PHP script):

echo "<form  action=\"nutzerverwaltung.php\" method=\"post\">";
echo "<table [...]";
    while ($row = $alluser->fetch_assoc())
    {
        echo "<tr>
    HERE--->    <td><input type=\"radio\" name=\"select_to_delete\" value=".$row["id"]."></td>
                <td>".ucwords(strtolower(str_replace(".", " ", $row["username"])))."</td>
                <td>".$row["username"]."@via-ev.de</td>
                <td>".$row["permissionlevel"]."</td>
            </tr>";
        }
        echo "</table><br />";
        echo "<input type=\"submit\" name=\"select_to_delete\" class=\"nv_button\" />
              </form>";
Jonas
  • 121,568
  • 97
  • 310
  • 388
JRsz
  • 2,891
  • 4
  • 28
  • 44
  • 2
    Both your radio and submit hold the same name attribute. I would call that a collision/conflict. Rename one. – Funk Forty Niner Jan 15 '15 at 20:11
  • isn't this to define that they all belong together? – JRsz Jan 15 '15 at 20:13
  • 1
    You can have radio buttons holding the same name attribute as an array, but not the submit button. Elements of the same "group" can have the same name attribute. – Funk Forty Niner Jan 15 '15 at 20:13
  • ok, that is good to know. But how do I get the value of the selected button in the $_POST array and how do I define the index? – JRsz Jan 15 '15 at 20:15
  • Well, that's where I'm stumped. You'll need to show us where you've defined it. I.e.: `$var=$_POST['select_to_delete'];` – Funk Forty Niner Jan 15 '15 at 20:19
  • I have not defined it. I have another form which works inthe same way. I had a very stupid typo in it, but here it is and it wirks perfedtly fine: http://stackoverflow.com/questions/27969615/html-form-submit-button-does-not-write-in-post – JRsz Jan 15 '15 at 20:21
  • 1
    So, problem solved then for this question? – Funk Forty Niner Jan 15 '15 at 20:22
  • Had of known, I'd of made that an answer 13 mins. ago. which was clearly the problem. – Funk Forty Niner Jan 15 '15 at 20:24
  • for your help you can still answer and I upvote it. You did help me! – JRsz Jan 15 '15 at 20:27
  • @JRsz You know that you can accept any answer at any time, so if you accept one it's not permanent... – Rizier123 Jan 15 '15 at 20:32
  • @Rizier123 It's ok. Let's leave it at that. I'm not in it for the points, it's the principle of the thing; doing the footwork as it were ;-) – Funk Forty Niner Jan 15 '15 at 20:35

2 Answers2

3

Putting my comments to an answer, since it was clearly the issue. As posted 17 mins. prior to my answer.

Both your radio and submit form elements hold the same name attribute.

I would call that a collision/conflict. Rename one, mainly your submit button.

You can have radio buttons holding the same name attribute as an array, but not the submit button. Elements of the same "group" can have the same name attribute.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
1

your submit input have the same name attribute just remove that

    echo "<input type=\"submit\" class=\"nv_button\" />

in html forms if you have inputs with same name the last one value will be send as your value

Kiyan
  • 2,155
  • 15
  • 15