Jump to content

Recommended Posts

You can store 1 for a checked box and 0 for an unchecked box. So..

 

Inserting:

 

$checkbox = (isset($_POST['some-check-box'])) ? 1 : 0;
//Insert $checkbox into mysql..

 

Getting back from the database:

 

//Query etc...
$checkbox = ($row['checkbox'] == 0) ? NULL : 'checked="checked"';
echo "<input type='checkbox' name='whatever' $checkbox />";

For that it's a bit different, you'd store the selected value and do something like this:

 

Storing:

$selected = mysql_real_escape_string($_POST['select-menu']);
//Query

 

Then for displaying it with the selected one:

 

//Query..
$items = Array('Menu Option 1', 'Menu Option 2', 'Menu Option 3');
foreach($items as $item)
{
     $menu .= ($row['selected'] == $item) ? "<option value='$item' selected='selected'>$item</option>" : "<option value='$item'>$item</option>";
}

 

Then $menu would contain the contents of the <select..></select>.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.