I have a very simple user update form, but I'm not able to successfully update using PDO and mysql.
Here is the snippet of code I'm having trouble with:
if (isset($_POST['ID'])){//Se informar o ID do usuário que deseja modificar
$senha = strip_tags(sha1(md5(trim($_POST['senha']))));//criptografa a senha
$ID = $_POST ['ID'];//recebe o ID informado pelo usuario para modificar no sql
if (!empty($_POST['NEWID'])){//modifica o ID
$sqlid = "UPDATE usuarios SET ID = :ID WHERE ID = $ID";
$stmtid = $pdo->prepare($sqlid);
$stmtid->bindParam(':ID', $_POST['NEWID'], PDO::PARAM_STR);
$stmtid->execute();
}
if (!empty($_POST['usuario'])){//modifica o usuario
$sqlusr = "UPDATE usuarios SET usuario = :usuario WHERE ID = $ID";
$stmtusr = $pdo->prepare($sqlusr);
$stmtusr->bindParam(':usuario', $_POST['usuario'], PDO::PARAM_STR);
$stmtusr->execute();
}
if (!empty($_POST['senha'])){//modifica a senha
$sqlpass = "UPDATE usuarios SET senha = :senha WHERE ID = $ID";
$stmtpass = $pdo->prepare($sqlpass);
$stmtpass->bindParam(':senha', $senha, PDO::PARAM_STR);
$stmtpass->execute();
}
}
The problem is that I can modify only 1 of these items at a time, if I want to modify the ID I can, but if I put it to modify the user also it will only modify the 1 item that in the case is the ID, my goal is to only make changes to the items that the user types ... I have already tried to do an execution only but the problem persisted ..