My code is supposed to edit a record in a database. I can insert fine but for some reason this is editing all of my records instead of just one im not sure if its the where clause. I am very new to this.
<!DOCTYPE html>
<html>
<head><title>Update User</title></head>
<body>
<!--this update the user from what you type into the form. IT will edit the user that you type its username, email and password-->
<?php
// variables
$username = $POST['username'];
$email = $POST['email'];
$password = hash('sha512', $_POST['password']);
$page_title = null;
$page_title = 'Update admin';
require_once('header.php');
// connects
require_once('db.php');
$Admin_id = $_POST['Admin_id'];
$sql = "INSERT INTO Admin (username, email, password) VALUES(:username, :email, :password)";
if (empty($Admin_id)) {
$sql = "UPDATE Admin SET username = :username, email = :email, password = :password";
}
else {
$sql = "UPDATE Admin SET username = :username, email = :email, password = :password WHERE Admin_id = :Admin_id";
}
if (!empty($Admin_id)) {
$cmd->bindParam(':Admin_id', $Admin_id, PDO::PARAM_INT);
}
// create the command, run the query and store the result
$cmd = $conn->prepare($sql);
$cmd->bindParam(':username', $username, PDO:😛ARAM_STR, 50);
$cmd->bindParam(':email', $email, PDO:😛ARAM_STR, 50);
$cmd->bindParam(':password', $password, PDO:😛ARAM_STR, 50);
$cmd->execute();
$Admin = $cmd->fetchAll();
$cmd->execute();
$conn = null;
require_once('footer.php');
?>
</body>
</html>