sho88 Posted October 28, 2010 Share Posted October 28, 2010 Hi guys, basically, I've got a web application I'm working on for someone; they want a system where they can book drivers, and they want a tick box where they can check the availability of a driver. The check box name is "field14" and has default value of "1" for ticked and "0" for unticked. Now, i've INSERT into the database a ticked box so in the "available" field is has "1" meaning yes, the people is available....but now the problem is if I want to tick off and say they're unavailable, how would I do that, because everytime I tick off it still represents the value of "1" and shows them as available.... Here is some code: if (($field14)==1) { echo "<p><label>ADR in Tank Class 1</label><input type='checkbox' name='field14' value='1' checked/></p><br /><br />"; } else { echo "<p><label>ADR in Tank Class 1</label><input type='checkbox' name='14' value='0'/></p>"; } I would really appreciate your help. Thanks Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 28, 2010 Share Posted October 28, 2010 I think you'd be better off using radio buttons for this particular application. Quote Link to comment Share on other sites More sharing options...
sharal Posted October 28, 2010 Share Posted October 28, 2010 try something like this: You will have to modify your code a little. By default when you submit a form with checkboxes, if its checked for instance $_POST['field14'] will be equal to 'On' if its not checked however $_POST['field14'] will be NULL, nothing that is. btw your second input field after the else block, the name of that is just '14' rather than 'field14', that could be it too. <?php if ($field14 == 'On') { echo "<p><label>ADR in Tank Class 1</label><input type='checkbox' name='field14' checked='checked'/></p><br /><br />"; } else { echo "<p><label>ADR in Tank Class 1</label><input type='checkbox' name='field14' /></p>"; } ?> as for inserting into the database with the values 1 and 0 you could do something like this: <?php $val; if($_POST['field14'] == 'On') { $val = 1; } else if(is_null($_POST['field14'])) { $val = 0; } // qry mysql_query("UPDATE mytable SET somefield = '$val'"); ?> Quote Link to comment Share on other sites More sharing options...
Andy-H Posted October 28, 2010 Share Posted October 28, 2010 Or you could typecast it to int: $field14 = (int)$_POST['field14']; Quote Link to comment 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.