0

i have table in mysql data with name of questions and it has two columns. Questionid-pk, Question-Text


i have just 5 questions in database and i am retrieving 5 questions from database and generating dynamic radio buttons. so i want when i click submit button am able to get values of each radio button. here is my code


<form   id="sny" name="sny"  action="" method="post" enctype="multipart/form-data">
        <?php
    if (!(isset($_POST['submit']))) {

    include("connect-db.php");
    $query_salutation_type="SELECT * FROM questions";
    echo $query_salutation_type;
    $select_salutation_type=mysqli_query($connection, $query_salutation_type);

    while($row1 = mysqli_fetch_array($select_salutation_type))
    {
       $name=$row1[0];
       echo $name;
       echo "<input type='radio' id='$name' name='$name' value='Yes' />Yes";
       echo "<input type='radio' id='$name' name='$name' value='Yes' />Yes";
       echo'<br />';
    }
    }
    ?>

<button type="submit" name="submit" id="submit"> Click now....!!!</button>           

          </form>

here am trying to get $post value after submit button click


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


                echo $_POST['1'];
echo $_POST['2'];
echo $_POST['3'];
echo $_POST['4'];
echo $_POST['5'];
}
?>

`

but i am receiving error

Notice: Undefined offset: 1 in C:\xampp\htdocs\hba\rnd.php on line


i hope you understand what am trying to do. kindly check my code thanks

roshi pandy
  • 25
  • 1
  • 7
  • 1
    Unchecked buttons are __not__ passed to server. – u_mulder Jul 10 '18 at 08:05
  • @u_mulder how i can get values of radio button after button submitted ? – roshi pandy Jul 10 '18 at 08:10
  • @u_mulder its not duplicate – roshi pandy Jul 10 '18 at 08:11
  • It'll depend on the value of `$name` when you submit the form. The `$_POST` superglobal is an associative array that uses the input names as keys; e.g. `` will be available via `$_POST['test']` - as long as that input is submitted of course (as noted above, unchecked buttons are not submitted). So unless your inputs are named `1`, `2`, `3` ... and so on, you script isn't going to work. – CD001 Jul 10 '18 at 08:58

0 Answers0