PHP: Getting the value of a radio button and storing it into a database -


i have never used radio buttons before. trying achieve is, using 2 radio buttons 'public' , 'private'. user's profile. html code buttons is;

<div class="btn-group" data-toggle="buttons-radio">     <button type="button" class="btn btn-primary" id="privacy" name="privacy"   value="0">private</button>     <button type="button" class="btn btn-primary" id="privacy" name="privacy"   value="1">public</button> </div> 

as php, i'm not sure how value , store it. appreciated!

use form.

<form method="get" action="yourscript.php">    <input type="radio" id="private" name="privacy" value="0">   <label for="private">private</label>    <input type="radio" id="public" name="privacy" value="1">   <label for="public">public</label>    <input type="submit" value="save">  </form> 

change buttons input elements, which, form, provide html native way send data script without need javascript (although can use javascript enhance usability later on).

using label tag, can assign text radiobutton. allows text clicked well, , provides better support screen readers, because can see text belongs radiobutton.

an id needs unique, changed private , public. ids used link label to.

the name determines name value sent script.

in php, can use superglobal $_get. $_get['privacy'] contain '0' or '1' depending on choice made. if method of form post, use superglobal $_post instead, or can use $_request, contains values either, in case script doesn't care whether values send in url (get) or in chunk of invisible post data sent along request.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -