Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio button

Status
Not open for further replies.

filipel

Programmer
Aug 13, 2007
42
PT
Hi.I have 2 radio buttons with name"newsletter".How can i store its value on a mysql table?
 
do you perhaps mean a radio group? in which case you will only ever receive no or 1 value from a browser. you would insert that value thus

Code:
if (isset($_POST['newsletter'])){
 $nlValue = 1;
} else {
 $nlValue = 0;
}
$sql = "Update table set newsletter=$nlValue where id=???";
mysql_query($sql) or die (mysql_error());

i.e. the secret is to test whether anything in the radio group has been set. if you are using string values for the group elements then change the first $nlValue to $nlValue = $_POST['newsletter'] and then remember to escape and enquote it before submitting to the database.
 
Ok.Thanks .But what datatype should i refer in mysql?Integer?
 
That would depend on what you are storing. if you are storing whether they are checked or not use a Boolean, if you want the actual value, either string or Integer depending on what is going to be stored.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top