I cannot get my update query to work in PHP

<?php
include "dbconn.php";

$sql = "UPDATE Employee SET firstname = ?, lastname = ?, email = ? WHERE EmployeeID = ?";
$id =  $_REQUEST["EmployeeID"];
$firstname = $_REQUEST["firstname"];
$lastname = $_REQUEST["lastname"];
$email = $_REQUEST["email"];
$statement = $conn->prepare($sql);

$statement->bind_param("sssi", $firstname,$lastname,$email,$id);
       
if ($statement->execute() == TRUE) {
  echo "window.location.href = 'employees.php'";
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

My connection to the database works fine hence I included my connection php file. I included a line of javascript to redirect me back to the homepage. When I try updating any of my records, I don’t get any errors however the values still remain the same. I’ve trying messing around with my prepared statement but I don’t see any errors in there. Any suggestions would be much appreciated as I’ve been going at this for a few days now thanks!

What output do you get on the page when the code runs?

Do you have php’s error_reporting set to E_ALL and display_errors set to ON, in the php.ini on your system, so that php will help you by reporting and displaying all the errors it detects?

Note: the window.location… line is javascript and would need to echo <script></script> tags around it in order for it to work. You also need a php exit; statement after it to stop php code execution.

Sponsor our Newsletter | Privacy Policy | Terms of Service