Problem with call in Database

Asked

Viewed 32 times

0

Next person I have several calls that update a database as the user fills the fields but specifically in the following error call in the database and not saved for anything, and all use the same calls just changing the data. Can someone fill up some error in this call that I’m not seeing?

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();

    }


}

}

  • na seguinte chamada da erro no banco de dados e não salva por nada. Okay, but what is the error that occurs ? Add to the question so we can help.

2 answers

0

I was able to solve the problem by putting 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);
  • So the error was exactly as I had said in my reply above, where when using a database field that is hyphenated, it is necessary to use some sort of quotation marks on it, otherwise the database does not recognize.

  • Got it, thanks buddy

  • No reason, we’re here to help

0


in the following line:

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

add the mysqli_error to know what’s wrong so:

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

But one thing, I saw that you have a bank field separated by a hyphen, in this case orgao-id, when using a field like this, you need to put between single quotes or crase: 'orgao-id', or instead of hyphenating, use underline.

  • When using mysqli_error() shows nothing, it seems that the error is not in sql... buguei now kkkk

  • @Marlonhenrique then is the second part I mentioned about quotation marks in fields separated by hyphen

Browser other questions tagged

You are not signed in. Login or sign up in order to post.