mardi 18 octobre 2016

How to detect uncheck box and send db query with php

Hi i am using the following code, and a simple one checkbox to detect if its 1 or 0 and if the check box is selected the value become 1 and its successfully working but when I am writing a code for unchecked box my logical task is not completing. the code is;

global $wpdb;

$myrows = $wpdb->get_var( "SELECT value FROM wp_geolocationdet" );
$fchk = $_POST["geolocrun"];


if (isset($fchk) && $fchk == "Yes"){
    $updatetable = $wpdb->update( 
    'wp_geolocationdet', 
    array( 
        'value' => '1', // string
    ), 
    array( 'activate' => 'status' ), 
    array( 
        '%s',   // value1
        '%d'    // value2
    ), 
    array( '%d' ) 
);
}



if (!isset($fchk)){
    $updatetable = $wpdb->update( 
    'wp_geolocationdet', 
    array( 
        'value' => '0', // string
    ), 
    array( 'activate' => 'status' ), 
    array( 
        '%s',   // value1
        '%d'    // value2
    ), 
    array( '%d' ) 
);
}

but the problem is when It detects that no checkbox is selected it automatically make the value in db '0' despite i unchecked it or just refresh the page it takes it as unchecked. How to over come this problem ? is there a way to truly detect that user unchecked the box ?




Aucun commentaire:

Enregistrer un commentaire