Error while passing index of an array

Asked

Viewed 26 times

0

Good night.

I believe my problem is simple, but I found nothing to cure it.

I’m doing a CRUD in PHP, using MVC, to learn how the language works. It turns out that the Mysql database works with date in yyy-mm-dd format and the date the user passes is dd/mm/yyyy. So far so good, the problem is that when I get the "data" field in my array, an error is returned saying that the index does not exist. Follow prints with explanation below.

Formulário HTML, onde consta o campo "cliente['data_nasc_cliente']" e chama a função insere.

Função insere, onde o erro é disparado.

Erro que me é apresentado.

Image 1: HTML form, which contains the "client['data_nasc_client']" field and calls the insert function.

Image 2: Function inserts, where the error is triggered.

Image 3: Error presented to me.

1 answer

0

You want to access a method that is not available for the variable: $_cliente['data_nasc_cliente'].

see:

$_cliente['data_nasc_cliente']->format('y-m-d'); 

To format a date you first need to build a date object:

$data = new DateTime($_cliente['data_nasc_cliente']) ;
$_cliente['data_nasc_cliente'] =  $data->format("Y-m-d");
  • It makes sense, but still the problem persists. Note that the error is "Undefined index".

Browser other questions tagged

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