undefined index

Asked

Viewed 55 times

0

I have a mistake of index indefinite, I’ve rewritten the code several times and I never find the why of the mistake, if anyone can help. I’m sorry if the question is badly formatted, because I’m new here and I didn’t learn to use the right tools

error:

Notice: Undefined index: aluno in C: xampp htdocs crud-complete removeAluno.php on line 4 {"error":false,"message":"Student successfully removed!"}

line 4: $student = json_decode($_POST["student"],true);

  <?php
    require_once("conexao.php");

    $aluno = json_decode($_POST["aluno"],true);

    $resposta["erro"]=false;
    $resposta["mensagem"]="";

    try{
        $sql="SELECT * FROM aluno WHERE id=:ID";
        $stmt = $conexao->prepare($sql);
        $stmt->bindParam(":ID", $aluno["id"]);
        $stmt->execute();

        $resultado=$stmt->fetchAll(PDO::FETCH_ASSOC);
        $resposta["data"] = $resultado[0];
    }catch(PDOException $e){
        $resposta["mensagem"] = "Erro ao carregar aluno. <br>{$e->getMessage()}";
        $resposta["erro"]= true;
    }

    echo json_encode($resposta);
?>
  • How are you making the request? Are you using a <form method="POST" />?

  • This happens because either the request for the PHP file was not made by the POST method or when no data was sent whose name "student".

  • t in the form, but I did not put the method

  • 1

    Try to put then, <form action="[ARQUIVO PHP]" method="POST">. When the method is not inserted. Then the form uses the standard (which is the GET method).

  • To learn more about these HTTP methods: https://answall.com/questions/300329/m%C3%A9todos-http-na-pr%C3%A1tica

No answers

Browser other questions tagged

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