Problem with call in database

0

Next I have several calls that update a database as the user is filling in the fields but specifically in the next error call in the database and not saved for anything, all of which use the same calls only changing the data. Can anyone get a bug in this call that I can not see?

if($op == 4) { 

$rg = $_POST["RG"];
$orgao = $_POST["orgao_rg"];
$cpf = $_POST["CPF"];
$fotofrente = $_POST["foto-id-frente"];
$fotoverso = $_POST["foto-id-verso"];

if($_POST["foto-id-frente"] && $_POST["foto-id-verso"]){
    usleep(enviar());
}

if(isset($_FILES['foto-id-frente']) && isset($_FILES['foto-id-verso'])){

    $extensao = strtolower(substr($_FILES['foto-id-frente']['name'],-4));
    $novonome = md5(time()).$extensao;
    $extensaoverso = strtolower(substr($_FILES['foto-id-verso']['name'],-4));
    $novonomeverso = md5(time()).'verso'.$extensaoverso;
    $diretorio = "documentos/";

    move_uploaded_file($_FILES['foto-id-frente']['tmp_name'], $diretorio.$novonome);
    move_uploaded_file($_FILES['foto-id-verso']['tmp_name'], $diretorio.$novonomeverso);

    $inserir = "UPDATE usuarios ";

    $inserir .= "SET ";

    $inserir .= "identidade = '$rg', orgao-id = '$orgao', foto-id-frente = '$novonome', foto-id-verso = '$novonomeverso', CPF = '$cpf' where id = '$id'";



    $operacao_inserir = mysqli_query($conexao,$inserir);

    if(!$operacao_inserir) {

        echo "<script language='javascript' type='text/javascript'>alert('Opss, erro no cadastro do banco de dados, estamos tentando corrigir!');</script>";

            die();

    }


}

}

    
asked by anonymous 20.11.2018 / 20:46

2 answers

0

in the following line:

$operacao_inserir = mysqli_query($conexao,$inserir);

add mysqli_error to find out what's wrong:

$operacao_inserir = mysqli_query($conexao,$inserir) or die(mysqli_error());

But one thing, I saw that you have a hyphen-separated bank field, in the org-id case, when using such a field, you need to enclose in single quotes or chasers: 'org-id' , or instead of using a hyphen, use underline.

    
20.11.2018 / 20:57
0

I was able to resolve the problem by placing the query in the following format:

    $inserir = "UPDATE 'usuarios' ";

    $inserir .= " SET ";

    $inserir .= " 'identidade' = '$rg', 'orgao-id' = '$orgao', 'foto-id-frente' = '$novonome', 'foto-id-verso' = '$novonomeverso', 'CPF' = '$cpf' WHERE 'usuarios'.'id' = $id ";

    $operacao_inserir = mysqli_query($conexao,$inserir);
    
21.11.2018 / 15:37