mardi 12 juillet 2016

Issue with PHP if/else values

Here's the relevant part of my code:

$json = file_get_contents('php://input');

$obj = json_decode($json, true);
$device_id =$obj['device_id'];
$num =$obj['sensor_value'];
$sensor_value =(int)$num;


if ($sensor_value > 100){
    $sql = "INSERT INTO rr_emergency (device_id,sensor_value) VALUES('$device_id','$sensor_value');";
    $result = $dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}
else {

    $sql = "INSERT INTO general_logging (device_id,sensor_value) VALUES('$device_id','$sensor_value');";
    $result = $dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}

The else statement works fine. However, when $sensor_value is greater than 100, the IF part of my statement never fires. What am I missing here?

Aucun commentaire:

Enregistrer un commentaire