set_charset('utf8mb4'); $dbh->query('CREATE DATABASE IF NOT EXISTS COMPANY_DB'); $dbh->select_db('COMPANY_DB'); $dbh->query('CREATE TABLE IF NOT EXISTS `SALARY` (`EMP_ID` INT PRIMARY KEY AUTO_INCREMENT, `EMP_NAME` VARCHAR(255), `BASIC_PAY` DOUBLE NOT NULL, `HRA` DOUBLE, `DA` DOUBLE, `PROFESSIONAL_TAX` DOUBLE)'); $result = $dbh->query('SELECT COUNT(*) AS count FROM `SALARY`'); $row = $result->fetch_assoc(); if ($row['count'] == 0) { $dbh->query('INSERT INTO `SALARY` (`EMP_NAME`, `BASIC_PAY`) VALUES ("Yu Jae-hoon", 70000), ("Meng Cilin", 65000), ("Mike Smith", 60000), ("Natsukashii Morimoto", 55000) '); } return $dbh; } function html_prologue($title) { ?> <?php echo $title; ?>

Operation failed

Reason:

query('SELECT * FROM `SALARY`'); ?>

Employee Salary Records

fetch_assoc()) { echo ''; } ?>
Employee NameBasic PayHRADAProfessional Tax
', $row['EMP_NAME'], '', number_format(+$row['BASIC_PAY'], 2), '', number_format(+$row['HRA'], 2), '', number_format(+$row['DA'], 2), '', number_format(+$row['PROFESSIONAL_TAX'], 2), '

Enter Salary Components

%
%
%
query('SELECT * FROM `SALARY`'); while ($row = $result->fetch_assoc()) { $hra = $row['BASIC_PAY'] * ($hra_percentage / 100); $da = $row['BASIC_PAY'] * ($da_percentage / 100); $ptax = $row['BASIC_PAY'] * ($professional_tax / 100); $stmt = $dbh->prepare('UPDATE `SALARY` SET `HRA` = ?, `DA` = ?, `PROFESSIONAL_TAX` = ? WHERE `EMP_ID` = ?'); $stmt->bind_param('dddi', $hra, $da, $ptax, $row['EMP_ID']); $stmt->execute(); } display_records($dbh); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { $dbh = connect_to_database(); calculate_salary($dbh); $dbh->close(); } catch (mysqli_sql_exception $e) { display_failure($e->getMessage()); } } else { show_salary_form(); }