0
    <body>
    <form method="post" action="index.php?module=membres&action=forum">
        <table id='forum'>
            <tr>
                <td>Choix de forums:</td>
            </tr>
            <tr>
                <td>Programmation</td>
                <td><input type="radio" name="forum" id="prog" value="prog"></td>
            </tr>
            <tr>
            <td>Reseau</td>
            <td><input type="radio" name="forum" id="reseau" value="reseau"></td>
            </tr> 

            <tr>
            <td>Etude</td>
            <td><input type="radio" name="forum" id="etude" value="etude"></td>
            </tr>
        </table>
         <input type="submit" value="Charger le forum">

    </form>
</body>



    <?php
if(isset($_POST['submit'])) {

    echo $id;
}
?> 

I am trying to make a form with radio buttons. When you click on submit after choosing your radio button, the current page is supposed to be "updated" and calling a function in my $_POST['submit']. The function is supposed to make appear a table with elements that it gets from the database. Now I am just trying to echo anything to see if my isset post is working or not but apparently no. I also need a way to keep my radio button clicked after the submit

locho30
  • 15
  • 6

2 Answers2

2

This is always false:

isset($_POST['submit'])

Because the form has no element with name="submit". You can simply add that to your submit button:

<input type="submit" name="submit" value="Charger le forum">
David
  • 208,112
  • 36
  • 198
  • 279
  • omg im so stupid.... and if i do echo $id, is the id of the clicked button supposed to appear? – locho30 Dec 12 '15 at 16:19
  • From the codesnipped you posted above, @Iocho30 there is no definition of `$id`. If you want to figure out what kind of radiobutton was clicked, `echo $_POST['forum']` inside the if-block and you will see the value of the one that was clicked. – Qirel Dec 12 '15 at 16:30
1

I recommend to use

var_dump($your_variable);

to debug PHP easlily. (There are better ways)

in order to make it more human readable, try enclosing var dump in "pre" tags like so

 <pre>
        var_dump($my_variable);
 <pre>
Jesus Rodriguez
  • 2,571
  • 2
  • 22
  • 38