I am trying to make a program that connects to a database and inserts some information to a table.
`<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$forename = $_POST["forename"];
$surname = $_POST["surname"];
$contractedHours = $_POST["contractedHours"];
$email = $_POST["email"];
echo "Hello World";
try {
require_once "dbh.inc.php";
$query = "INSERT INTO `employees`(`forename`, `surname`, `contractedHours`, `email`) VALUES (?, ?, ?, ?);";
$stmt = $pdo->prepare($query);
$stmt->bindParam(":forename", $forename);
$stmt->bindParam(":surname", $surname);
$stmt->bindParam(":contractedHours", $contractedHours);
$stmt->bindParam(":email", $email);
$stmt->execute();
$pdo = null;
$stmt = null;
header("Location: ../test.php");
die();
} catch (PDOException $e) {
die("Query Failed: " . $e->getMessage());
}
} else {
header("Location: ../test.php");
exit;
}`
The database is currently unable to connect which is a separate problem but when the code is run, it always ends up in the else branch of the if statement. However, it leaves me on a white screen, without redirecting to the 'test.php' page. I have tried using obj_start() and obj_end() but these do not fix my issue. Any ideas how to solve this?