Jump to content

Archived

This topic is now archived and is closed to further replies.

angel2006

checkbox help

Recommended Posts

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?

thanks

Share this post


Link to post
Share on other sites
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[code]if(!is_set($_POST['checkbox'])) $_POST['checkbox']=0;[/code]

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

Share this post


Link to post
Share on other sites
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.

[code]<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!'>

</form>[/code]

code.php:

[code]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]'");

}[/code]

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

Share this post


Link to post
Share on other sites

×

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.