mysql - Submit button only sees the multiplequestions as onequestion using php and database -


so have problem. when select radio button of question 1 example selects radio button. when select radio button different question, first radio button i've selected isn't selected anymore , other radio button selected. i've tried searching solution,but can't find any. it's school project, have make poll. here's code:

<?php  mysql_connect("  ", "    ", "   "); mysql_select_db("  ") or die(mysql_error());  if(isset($_post['verzenden'])) { $query="update optie set stemmen = stemmen + 1 id='" . $_post['item']. "'"; } if(mysql_query($query)){ echo"stem opgeslagen! <br /><br/>"; } else { echo"fout tijdens opslaan stem!<br /><br/>"; }  $result = mysql_query("select * poll");  while($data = mysql_fetch_assoc($result)){  echo"<b>" . $data['vraag'] . "</b><br/><br />";  echo"<form method='post' action=''>"; echo "<fieldset>";  $result2 = mysql_query("select * optie poll ='" . $data['id'] . "'"); while($data2 = mysql_fetch_assoc($result2)){ echo"<input type='radio' name='item' value='" . $data2['id'] . "'/>" . $data2['optie'] . "<br />"; } echo"<br/>"; echo"</fieldset>"; } ?> <input type='submit' name='verzenden' value='verzenden'> </form>  <a href="checkbox.php">ga verder</a> 

i hope can me. bye, catherine

that's happening because of radio button sets have same name: item. here couple ways can make radio button sets unique; pick 1 that's best you.

  1. append poll.id value each button name:

    $result2 = mysql_query("select * optie poll ='" . $data['id'] . "'"); while($data2 = mysql_fetch_assoc($result2)){   echo"<input type='radio' name='item_" . $data['id'] . "' value='" . $data2['id'] . "'/>" . $data2['optie'] . "<br />"; } 
  2. append sequence number each button name:

    $result2 = mysql_query("select * optie poll ='" . $data['id'] . "'"); $buttonnumber = 0; while($data2 = mysql_fetch_assoc($result2)){   ++$buttonnumber;   echo"<input type='radio' name='item_$buttonnumber' value='" . $data2['id'] . "'/>" . $data2['optie'] . "<br />"; } 

finally, note mysql_query family of functions deprecated because can leave vulnerable sql injection attacks. see here , other places information using mysqli or pdo instead.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -