how to store chechbox value in php
I have checkbox of condition apply where I want to store 开发者_JS百科string value "Condtion Apply". But, I get inserted error so give solution how to store value in database
HTML could be something like:
<input type="checkbox" name="condapply"/> Apply to conditions
In case you don't check the checkbox there will be no transmitted POST-variable after you clicked the submit-button.
So on the other side (php) you should use something like:
// evalutes if the value has been set
$dbval = isset($_POST['condapply']) ? '1' : '0';
$dbval will always contain some ready-to-store-in-db value. In this case eigther '1' or '0'.
Here is an example
-- php -- $food = $_POST['food']; -- end php --
-- html -- form method="post" action="?php echo $PHP_SELF;?>"
Please choose type of residence::
Steak:input type="checkbox" value="Steak" name="food[]">:
input type="submit" value="submit" name="submit">
/form>
-- end html --
You might need to correct the syntax of the code in order to work correctly. the tags. after you get the value to the $food variable (this will be an array() ) you can update to the db.
精彩评论