<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "test_db";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//check radio button and update sql accordingly
if (isset($_GET['calc'])) {
$calc = $_GET['calc'];
}
if ($calc='average'){
$sql1 = "UPDATE `config` SET `calc_category`=1 WHERE 1";
$conn->query($sql1);
} elseif ($calc='high'){
$sql1 = "UPDATE `config` SET `calc_category`=2 WHERE 1";
$conn->query($sql1);
} else {
$sql1 = "UPDATE `config` SET `calc_category`=3 WHERE 1";
$conn->query($sql1);
}
?>
In the above code even if the $calc is equal to 'high' or something other than 'average', it still updates the database with 'calc_category'=1 which is only supposed to happen when first 'if' condition is true.
I have echoed the value of $calc and it changes based on which radio button is selected but I am not sure why always first 'if' condition code is getting executed.
I am new to PHP,SQL please help me where am I going wrong.