php - simple yes or no checkbox for forms -


i have inserted checkbox in form.

my code:

<input type="checkbox" id="checkbox" name="checkbox" value="1"/>  if($checkbox = ($_post['checkbox']) == '1')         {             $checkbox = "si";         }         else         {             $checkbox = "no";         } 

i if checkbox checked receive "yes" otherwise "no". thanks.

you've written wrong if condition here, cannot use assignment in conditions.

also there no need assign value variable in checking condition, can directly use $_post['checkbox']. this,

if($_post['checkbox'] == '1') {    $checkbox = "si"; } else {    $checkbox = "no"; } 

update:

a better option use isset() determine if variable set , not null. this,

if(isset($_post['checkbox'])) {    $checkbox = "si"; } else {    $checkbox = "no"; } 

program go in if condition when user has checked checkbox. in above case value attribute <input> not required. html this,

<input type="checkbox" id="checkbox" name="checkbox"/> 

Comments

Popular posts from this blog

Lists in Python -

android - can not access to progress bar in an other activity -

html - Not able to access next element of an array javascript -