Warning: Pdostatement::execute(): SQLSTATE[HY093]

Asked

Viewed 141 times

1

Goodnight!

I am mounting a CRUD, I took some codes on the Internet and adapted to my need, everything was going perfectly well, but when I got to the UPDATE part the application presents me the following error: Warning: Pdostatement::execute(): SQLSTATE[HY093].

I would like your help to solve my problem.

Follows Code:

<?php

 $id=isset($_GET['id']) ? $_GET['id'] : die('ERROR: ID não encontrado.');

 include 'config/database.php';

 if($_POST){

     try{

     $query = "UPDATE alunos SET nome=:nome, responsavel=:responsavel, telefone=:telefone, ensino=:ensino, serie=:serie, visita=:visita, entrevista=:entrevista, teste_data=:teste_data, teste_result=:teste_result, matricula=:matricula, data_matricula=:data_matricula, observacao=:observacao WHERE id = :id";

     $stmt = $con->prepare($query);

     $nome=htmlspecialchars(strip_tags($_POST['nome']));
     $responsavel=htmlspecialchars(strip_tags($_POST['responsavel']));
     $telefone=htmlspecialchars(strip_tags($_POST['telefone']));
     $ensino=htmlspecialchars(strip_tags($_POST['ensino']));
     $serie=htmlspecialchars(strip_tags($_POST['serie']));
     $visita=htmlspecialchars(strip_tags($_POST['visita']));
     $entrevista=htmlspecialchars(strip_tags($_POST['entrevista']));
     $teste_data=htmlspecialchars(strip_tags($_POST['teste_data']));
     $teste_result=htmlspecialchars(strip_tags($_POST['teste_result']));
     $matricula=htmlspecialchars(strip_tags($_POST['matricula']));
     $data_matricula=htmlspecialchars(strip_tags($_POST['data_matricula']));
     $observacao=htmlspecialchars(strip_tags($_POST['observacao']));

     $visita=date("Y-m-d",strtotime(str_replace('/','-',$visita)));
     $entrevista=date("Y-m-d",strtotime(str_replace('/','-',$entrevista)));
     $teste_data=date("Y-m-d",strtotime(str_replace('/','-',$teste_data)));
     $data_matricula=date("Y-m-d",strtotime(str_replace('/','-',$matricula)));    

     $stmt->bindParam(':nome', $nome);
     $stmt->bindParam(':responsavel', $responsavel);
     $stmt->bindParam(':telefone', $telefone);
     $stmt->bindParam(':ensino', $ensino);
     $stmt->bindParam(':serie', $serie);
     $stmt->bindParam(':visita', $visita);
     $stmt->bindParam(':entrevista', $entrevista);
     $stmt->bindParam(':teste_data', $teste_data);
     $stmt->bindParam(':teste_result', $teste_result);
     $stmt->bindParam(':matricula', $matricula);
     $stmt->bindParam(':data_matricula', $data_matricula);
     $stmt->bindParam(':observacao', $observacao);

     if($stmt->execute()){
         echo "<div class='alert alert-success'>Atualização realizado com sucesso.</div>";
        }else{
         echo "<div class='alert alert-danger'>Não foi possível atualizar o registro. Por favor, tente novamente.</div>";
     }

     }

 catch(PDOException $exception){
     die('ERROR: ' . $exception->getMessage());
 }
 }?>

Thanks for your help.

1 answer

0

Missed passing Where’s ID.

$stmt->bindParam(':observacao', $observacao);
$stmt->bindParam(':id', $_GET['id']);
  • Before answering I recommend that you search http://answall.com/search?tab=votes&q=SQLSTATE%20HY093

  • Following the reference you gave me, I pointed out a mistake and presented a solution...

  • 1

    http://answall.com/help/duplicates and not mine, I’m just telling you to search and if there is already answer mark as duplicate, we are not a forum, here we follow a specific model to organize the content.

  • 2

    I understand. Thank you :)

  • Thank you and welcome to the site ;)

Browser other questions tagged

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