angel2006 Posted April 20, 2006 Share Posted April 20, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/7997-checkbox-help/ Share on other sites More sharing options...
michaellunsford Posted April 20, 2006 Share Posted April 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7997-checkbox-help/#findComment-29170 Share on other sites More sharing options...
Caesar Posted April 20, 2006 Share Posted April 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7997-checkbox-help/#findComment-29172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.