-1
I have a very simple user update form, but I am not able to successfully update using PDO and mysql.
Follow the excerpt of the code I’m in 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 to modify the user also it will modify only the 1 item that in the case is the ID, my goal is to make it only be modified the items that the user type... I tried to do an execution only but the problem persisted..
But if you modify the ID and then try to modify the USER, the table ID will not be the ID you are comparing, but the ID that is coming by POST['NEWID'].
– Don't Panic
really, but in the case had already tried to do it at once with the execute and still persisted, if I performed everything together he should not do all? since the ID would only modify after the run, good anyway was really this! If you can answer the question to close the topic I would be grateful! really the most difficult is to see our mistakes..
– Wel