For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > November 2006 > radio buttons, checkboxes and dropdown menues









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author radio buttons, checkboxes and dropdown menues
Gaga

2006-11-23, 3:58 am

Hi to all !

How to insert one value of the radio button int db. ?
<input type="radio" name="option" value="male">
<input type="radio" name="option" value="female">

----------------------------------------------------------
How to make the same but with checkbox ?
<input type="checkbox" name="checkbox" value="male">
<input type="checkbox" name="checkbox" value="female">

---------------------------------------------------------
How to insert selected value from the dropdown menu ?
<select name="year" id="year">
<option>2005</option>
<option>2006</option>
</select>

---------------------------------------------------------------------


J.O. Aho

2006-11-23, 7:59 am

Gaga wrote:
> Hi to all !
>
> How to insert one value of the radio button int db. ?
> <input type="radio" name="option" value="male">
> <input type="radio" name="option" value="female">
>
> ----------------------------------------------------------
> How to make the same but with checkbox ?
> <input type="checkbox" name="checkbox" value="male">
> <input type="checkbox" name="checkbox" value="female">
>
> ---------------------------------------------------------
> How to insert selected value from the dropdown menu ?
> <select name="year" id="year">
> <option>2005</option>
> <option>2006</option>
> </select>
>
> ---------------------------------------------------------------------
>
>


/* assume you have already connected to database and you use mysql */

/* change the "option" in the $_REQUEST[] to the name you used in the form */
$query="INSERT INTO table(column_name) VALUES('".$_REQUEST['option']."')";
/* if you use another database, change the mysql part to the one for your
database or odbc if your database isn't supported by php */
mysql_query($query);

As checkboxes may generate more than one value, the $_REQUEST['checkbox'] may
be a array in which you have to make a for loop.


//Aho
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com