title: Create a survey form in php
body: <p>The survey questions comes from the database, but the options are static. </p>
  
  <p>The code runs only for first question, answer. Other questions cause an error. It's looping data but it takes only first ID, which is why it gives the proper result for first one only. I can't do it for all. </p>
  
  <p>How can i solve it? Data store using Ajax and PHP? Please ignore my script run. i don't give full code, that's why it shows error. </p>
  
  <p><strong>JavaScript Code:</strong><br>
  What is the correct code?</p>
  
  <pre><code>$('#submit-button').click(function () {
      var qns_id= $('#qns-id').val();
      if(qns_id&gt;0){
          if(document.getElementById('option1').checked) {
              var ans = $('#option1').val();
          }else if (document.getElementById('option2').checked){
              ans =$('#option2').val();
          }else if (document.getElementById('option3').checked){
              ans =$('#option3').val();
          }
          console.log(ans,qns_id);
      }else{
          alert ('0 result');
      }
  });
  </code></pre>
  
  <p><strong>PHP/HTML Code:</strong><br>
  Is this format is right? Is it possible that the questions are dynamic but the options are static? If possible, please help me with this problem. If not possible then tell me what process I can follow for my project. </p>
  
  <pre><code>&lt;?php
  require_once('inc/config.inc.php');
  $conn= mysqli_connect(WIFI_SERVER_NAME, WIFI_USER_NAME, WIFI_PASSWORD,WIFI_DB_NAME);
  if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
  }
  $sql = "SELECT survey_quiz_id, title FROM survey_quiz";
  $result = mysqli_query($conn, $sql);
  ?&gt; 
  &lt;div class="form-group" id="blockSurvey"&gt;
      &lt;div class="logo-container title-top-med"&gt;
          &lt;h2&gt;Survey for Improvement&lt;/h2&gt;
      &lt;/div&gt;
      &lt;div class="survay-form"&gt;
          &lt;form method="post" name="survay"&gt;
              &lt;div class="title"&gt;
                  &lt;?php
                  if (mysqli_num_rows($result) &gt; 0) {
                      while($row = mysqli_fetch_assoc($result)) {
                  ?&gt;
                  &lt;h2&gt;
                  &lt;?php echo $row['title']; ?&gt;
                      &lt;input type="hidden" id="qns-id" name="qns-id"  value="&lt;?php echo $row['survey_quiz_id']; ?&gt;"&gt;
                  &lt;/h2&gt;
                  &lt;div class="options" id="value"&gt;
                      &lt;ul&gt;
                          &lt;li&gt;&lt;input type="radio" id="option1" name="ans"  value="Not Good"&gt;&lt;p class="double-word"&gt;Not Good&lt;/p&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;input type="radio" id="option2" name="ans"  value="Good"&gt;&lt;p class="single-word"&gt;Good&lt;/p&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;input type="radio" id="option3" name="ans" value="Very Good"&gt;&lt;p&gt;Very Good&lt;/p&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
                  &lt;?php
                      }
                  } else {
                      echo "0 results";
                  }
                  ?&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;div class="btn btn-primary btn-survey" id="submit-button"&gt;Submit&lt;/div&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt; 
  </code></pre>