Jump to content

Checkbox Displaying Boolean Data From Database


Recommended Posts

//The ckeckbox type has only one possible value per input: off(unchecked) or on(checked). The database field which records this information is almost always going to be a samll integer or bit type with values 0 and 1 corresponding to unchecked or checked check boxes.

//The following example demonstrates how to use a check box to DISPLAY and CHANGE a BOOLEAN value.


//Open connection to the database

mysql_connection("localhost", "phpuser", "sesame") or die("Failure to communicate with database");


//If the form has been submitted, record the preference and redisplay




if(isset($_post['optout'] && $_post['optout']==1)







//Update value

$query="update checkbox set boxvalue=$optout where boxname='optout' and email='$as_email'";


if(mysql_error()==" ")


$succes_msg='<p>Your preference has been updated.</p>';





//Get the value

$query="select boxvalue from checkbox where boxname='optout' and email=='$as_email'";


$optout=mysql_result($result, 0, 0);



$checked=" ";







//Now display the page


//Have to do this for heredoc







<form method="post" action="$thispage">

Email address:

<input type="text" name="email" size=25 value="$email">



<font size=+4>please send me lots of e-mail bulletins!</font>


<font size=-2>Opt out by clicking this tiny checkbox</font>

<input type="checkbox" name="OptOut" value=1 $checked>



<input type="submit" name="submit" value="Submit">





echo $form_page;


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.