Jump to content

Code for Radio Button


newphpcoder

Recommended Posts

Good day!I never used radio button. Now I need to add radio button in my webpage. Radio button 1 is mother and radio button 2 is child. Is it in my database it is only 1 field or separate field one for mother and one for child?Kindly give me a code for radio button.Thank you...

Link to comment
Share on other sites

See http://www.w3schools.com/html/html_forms.asp for information on creating radio buttons.<form><input type="radio" name="xyz" value="mother" /> Mother<br /><input type="radio" name="xyz" value="child" /> Child</form>"xyz" can be changed to whatever you want, but both inputs must have the same name.In your page which handles the form the user's selection will be in $_GET['xyz'] (or if your form is post then $_POST['xyz']).

Link to comment
Share on other sites

See http://www.w3schools.com/html/html_forms.asp for information on creating radio buttons.<form><input type="radio" name="xyz" value="mother" /> Mother<br /><input type="radio" name="xyz" value="child" /> Child</form>"xyz" can be changed to whatever you want, but both inputs must have the same name.In your page which handles the form the user's selection will be in $_GET['xyz'] (or if your form is post then $_POST['xyz']).
What should be the field type of xyz in the database?Thank you
Link to comment
Share on other sites

use of radio buttons only return one value from a group with same name, so you can just use one field called 'relationship' using type varchar to store both 'mother' or 'child'.using checkboxs with same group name, will store multiple values, but these can also be stored using 1 field of type varchar, but because the values are passed as an array of values, you will have to use php serialize() to pass values to the field, and unserialize() to retrieve the values.serialize()

$relationships=serialize($_POST['relationships']);$query=INSERT INTO relationships VALUES('$relationships');

unserialize()

$query=SELECT * FROM mytable;$doQuery=mysql_query($query);$numrows=mysql_num_rows($doQuery);if($numrows>0){ while($relationships=mysql_fetch_array($doQuery))  {  $relationships=unserialize($relationships['relationships']);	  foreach($relationships as $relation)   {	  print $relation.', ';   }  }}else{ print 'No relationships found.';}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...