Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-09-2005, 06:20 AM   #1
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 670
Blog Entries: 7

Rep: Reputation: 31
checkboxes in php [on/off]

I want to add a checkbox to my form that should act as a on off regulator..........I googled but the only results I found were related to multiple checkboxes.........can anybody tell me how to check if a single checkbox is checked ?
Old 11-09-2005, 06:40 AM   #2
Senior Member
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
Something like this would be in your form:
<input type='checkbox' name='a1'<?php if( $row["a1"] == '1') { echo "CHECKED"; } ?>>Block / Unblock Website
which is then read in by your processing script as such:
$a1 = $HTTP_POST_VARS["a1"];
In that case, my script is querying a MySQL database, working out whether an option should be ticked, and then ticking or unticking the check box. Has about 30 options dynamically handled, with the procesing script updating the choices the user makes. You can call it something other than 'a1' and then simply read in your named variable whilst processing. If it's unchecked, the result is 'off', if ticked, the result is 'on'. A quick check to process different commands based on it's value would be:
if ($a1 === 'on') {
		$a1 = 1;
Hope it helps, otherwise let us know what you're trying to do.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unsubscribe From [ ] (checkboxes) t3gah LQ Suggestions & Feedback 5 06-02-2005 12:12 PM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM
Arrays, checkboxes in javascript & PHP Elijah Programming 21 11-15-2004 11:37 PM
Checkboxes in the Subscribed Threads listing Bebo LQ Suggestions & Feedback 2 07-21-2004 09:30 AM
MySQL/PHP - checkboxes etc linuxfond Programming 2 05-07-2004 04:12 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:41 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration