Jump to content

Checkboxes & MySQL

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Hey!

I want to use a Checkbnox where a user can select something

But I want the checkbox to stay checked if the user reloads the page.

It would check wether to check it from a mysql dat

How would I do this?

#2
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Like:

<input type='checkbox' name='myCheckbox' value='myValue' <?php if($_POST['myCheckbox'] == 'myValue') { echo "checked"; } ?>>

This will make it checked when page is reloaded for form submission. Though if you want it to still be checked if page is just reloaded without any form submission, then it'll require AJAX or might be able to be done with normal javascript as well. Let me know if you need that done =].

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
by definition, the attribute checked shall have value checked, so it becomes

<input type='checkbox' name='myCheckbox' value='myValue' <?php if($_POST['myCheckbox'] == 'myValue') { echo 'checked="checked"'; } ?>>
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#4
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Hmm I see, for me just adding 'checked' to the tag worked fine, but what you say might be more correct.