INSERT command in php is not working

Asked

Viewed 188 times

0

I’m passing a PHP project I did on the local server to a paid server. When I was only using the location of my machine, everything worked. However, when I passed the whole program to the new server, the problem appeared. I am using the Postgresql database, and when trying to execute an INSERT command, to insert the data in the BD, appears the message that was registered but is not registered in the BD. The DELETE and UPDATE commands are working normally. Follow the code

$inserir = $pdo->prepare("INSERT INTO produtos values (nextval('produto_id_seq'::regclass),:nome, :preco,:tipo,  :imagem, :medida, :observacao);");
                        $inserir->bindParam(':nome', $nomeprod, PDO::PARAM_STR);
                        $inserir->bindParam(':preco', $preco, PDO::PARAM_STR);
                        $inserir->bindParam(':tipo', $tipo, PDO::PARAM_STR);
                        $inserir->bindParam(':imagem', $novoNome, PDO::PARAM_STR);
                        $inserir->bindParam(':medida', $medida, PDO::PARAM_STR);
                        $inserir->bindParam(':observacao', $observacao, PDO::PARAM_STR);
                        $inserir->execute();
  • Do if(!$inserir->execute()){ print_r($stmt->errorInfo()); } and see if any error appears, if yes edit the question and add it :)

  • Not even an error appeared putting this line of code.

  • If you run this insert directly in the error production bank?

  • I already tested an INSERT with data ready and when running in the database it worked perfectly, after that, I copied the same INSERT to test by the program, and the error continued.

  • Ah, now the error has appeared, it was the following Array([0] => 42501 [1] => 7[2] => ERRO : permissão negada para sequência produto_id_seq) @rray

  • I would try to solve it this way first, instead of nextval() send a null if not sure would check the issue of Quenquence’s permission. At least now have an error to fix :)

  • I set the null and the following appeared erro: valor nulo na coluna "id_produto" viola a restrição não-nula @rray

  • If you specify the column names with the respective values and of course do not include the id_produto ?

  • When doing this, the initial error returns. (permission denied for sequence)

  • 1

    you are using pgAdmin or phpPgAdmin? can give permission in Quence there?

  • 1

    I also thought about it, I was going through the permissions and apparently there is only permission for UPDATE and SELECT, I just contacted the provider to release the permission. If it works, I return here to report. Thank you for your attention

Show 6 more comments

1 answer

1

The problem was only in the same privilege, as said. I asked the provider to release to me(In fact I myself could have released such a privilege), and it worked. Thank you for your attention.

Browser other questions tagged

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