In my inventory management app for the update functionalities, after setting up the sql I'm executing the $stmt
and if it executed successfully I'm headed to the home page. Otherwise do some other actions. And in the if statement where I'm preparing the sql command and executing it, I'm closing the $stmt
with $stmt->close()
. But this throws me the error above. I followed some other question answers where they suggested to move the close()
line inside the if statement. But it didn't work.
Update.php
// Check input errors before inserting in database
if(empty($itemname_err) && empty($itemnumber_err) && empty($cost_err)&& empty($details_err)){
// Prepare an update statement
$sql= "UPDATE inventory SET itemname=$itemname, itemnumber=$itemnumber, cost=$cost,details=$details, WHERE id = $id";
if($stmt = $mysqli->prepare($sql)){
// Set parameters
$param_itemname = $itemname;
$param_itemnumber = $itemnumber;
$param_cost = $cost;
$param_details = $details;
$param_id = $id;
//$stmt->bind_param("sssss", $param_itemname, $param_itemnumber, $param_cost, $param_details, $param_id);
// Attempt to execute the prepared statement
if($stmt->execute()){
// Records updated successfully. Redirect to landing page
header("location: index.php");
exit();
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
$stmt->close(); // here's the problem line
}
// Close connection
$mysqli->close();
}else{
...
}
I tried checking the sql but it seemed fine to me. So any suggestions?