1
Hello I am making an administrative panel where the administrator can edit the Name, User and email but it does not perform the UPDATE in the database but in the message it says that the update follows the Update code.
<?php
include_once("conexao.php");
$servidor = "fdb17.atspace.me";
$usuario = "2443930_braban";
$senha = "minhasenha";
$dbname = "2443930_braban";
//Criar a conexao
$conn = mysqli_connect($servidor, $usuario, $senha, $dbname);
//selecionando o banco de dados
$db = mysqli_select_db($conn, "2443930_braban");
//criando a query de consulta à tabela criada
$sql = mysqli_query($conn, "SELECT * FROM usuarios") or die(
mysqli_error($conn) //caso haja um erro na consulta
);
$id = $_POST["id"];
$nome = $_POST["nome"];
$email = $_POST["email"];
$usuario = $_POST["usuario"];
$result_usuario = "UPDATE usuarios set nome ='$nome', usuario = '$usuario', email = '$email', WHERE id='$id'";
$resultado_usuario = mysqli_query($conn, $result_usuario);
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
</head>
<body>
<?php
if (mysqli_affected_rows($conn) != 0 ){
echo "
<META HTTP-EQUIV=REFRESH CONTENT = '0;URL=http://braban.atspace.tv/dados/admin/ccbo/adm2/administrativo.php?link=2'>
<script type=\"text/javascript\">
alert(\"Usuário editado com Sucesso.\");
</script>
";
}
else{
echo "
<META HTTP-EQUIV=REFRESH CONTENT = '0;URL=http://braban.atspace.tv/dados/admin/ccbo/adm2/administrativo.php?link=2'>
<script type=\"text/javascript\">
alert(\"Usuário não foi editado com Sucesso.\");
</script>
";
}
?>
</body>
</html>
Tip : Under your mysqli_query add printf("Error message: %s n", mysqli_error($Conn)); Which message gives ?
– Rafael Salomão
not error message says User edited successfully but does not edit anything
– mateus silva
Added the printf with mysqli_error($Conn) after running your querie ?
– Rafael Salomão
$result_usuario = "UPDATE usuarios set name ='$name', usuario = '$user', email = '$email', WHERE id='$id'"; has no comma after ", email = '$email', WHERE" . Take off that comma!
– Rafael Salomão
added raphael showed no error and pulled out the vergula now shows User has not been edited successfully.
– mateus silva
So when it is like this and leaves lost agent, usually before the query we have it printed like this : echo "UPDATE usuarios set name ='$name', user = '$user', email = '$email', WHERE id='$id'"; we take the result and run directly inside the bank, must have some variable sent by empty POST like $id; mysql_error should report error in the querie. Print the querie on the page and check the result.
– Rafael Salomão
if I put a SESSION will work would?
– mateus silva
Let’s go continue this discussion in chat.
– Rafael Salomão