how to save checkbox value into mysql database using php

前端 未结 3 1936
眼角桃花
眼角桃花 2021-01-22 19:16

hi i have a form which has a checkbox and i want to save the value of the checkbox into my database but when i click on the checkbox and save it it works fine and when i try to

相关标签:
3条回答
  • 2021-01-22 19:50

    If the checkbox is not checked, the value is not posted to the script. You must check if it is set before using it.

    if(isset($_POST['active'])){
        //do something if is
    }
    else{
        //do something if not
    }
    
    0 讨论(0)
  • 2021-01-22 19:57

    If the checkbox isn't checked, the browser won't actually send the data in your POST request. You'll need to check if the value is set, and then update your variable accordingly.

    $inactive = isset($_POST["active"]) ? $_POST["active"] : 0;

    0 讨论(0)
  • 2021-01-22 20:16

    Use an isset control in the next page like this :

    if (!isset($nactive)) $nactive = 0;
    

    If your checkbox isn't checked, the value will be 0

    0 讨论(0)
提交回复
热议问题