Jump to content


checkbox help

  • Please log in to reply
2 replies to this topic

#1 angel2006

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 20 April 2006 - 09:59 PM

could someone pls tell me how tp create a checkbox which will be for yes or no.if its checked it should show that in the table.

at the moment i have a field in a table set to tinyint(1), is that right?


#2 michaellunsford

  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 20 April 2006 - 10:31 PM

your database setting is fine (that's what I use) -- but remember that an unchecked checkbox will not show up in your $_POST or $_GET variables.

So, you will have to accommodate the fact that a variable might not come across.

something like
if(!is_set($_POST['checkbox'])) $_POST['checkbox']=0;

Lately, I've been using radio or select groups with a yes and no option.

#3 Caesar

  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 20 April 2006 - 10:41 PM

if you are giving people either a yes or no option, you want to use a radio button. It would make life easier for you.

<form method='post' action='code.php'>

<input type='radio' name='decidethis' value='1'>Yes<br>
<input type='radio' name='decidethis' value='0'>No<br>

<input type='submit' name='doit' value='Do It!'>



if(($_POST['doit'] > '') && ($_POST['decidethis'] >''))


$table = 'your_table';

$column = 'your_column';

$answer = $_POST['decidethis'];

mysql_query("INSERT INTO $table ($column) VALUES ($answer) WHERE id = '$current_user[id]'");


...Something to that effect. Good luck buddy.
PHP Ninja

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users