2

I have form in webpage where users have to fill in their information and some of them are: birth date, description, education and city. If user add only birth date (or any other field + birth date) and clicks save, than everything is ok, info in database is updated. But if birth date field is left blank then info is not updated and there is an error:

Object Moved
This document may be found here
1292:Incorrect date value: '--' for column 'birth_date' at row 1
UPDATE users SET `avatar` = '01\\14',`birth_date` = '--' WHERE user_id = '13'"

Part of the function where system is checking if fields are empty:

    if ( !empty( $Request->post['birth_date'] ) ) {
        $user_data['birth_date'] = implode('-', $Request->post['birth_date'] );
    }

    if ( !empty( $Request->post['description'] ) ) {
        $user_data['description'] = $Request->post['description'];
    }

    if ( !empty( $Request->post['education_id'] ) ) {
        $user_data['education_id'] = $Request->post['education_id'];
    }
    if ( !empty( $Request->post['city_id'] ) ) {
        $user_data['city_id'] = $Request->post['city_id'];
    }

My question is why this checking if field is not empty does not work for date?

P. S. in mysql database birth_date type is date, description type is text and the other two are integers.

Blaze
  • 33
  • 6
  • Can you post your html form? – hamed Sep 11 '15 at 14:11
  • 3
    Can you also post the code where you use `$user_data['birth_date'] ` as a parameter to a database query. That is where you are getting the data format wrong. Also show how the `birth_date` input field(s) from your form – RiggsFolly Sep 11 '15 at 14:12
  • 1
    Of course you can ignore all these suggestions and we move on to another question where the questioner is bothered enough to make some sort of reply.... – RiggsFolly Sep 11 '15 at 14:22
  • 1
    Looks like $Request->post['birth_date'] is an array, therefore not empty. – Kickstart Sep 11 '15 at 14:24
  • You claim to be a `computatinal linguist` well it seems that the `computational` bit is sadly lacking and the `linguist` bit is all but non existant. I am out of here! – RiggsFolly Sep 11 '15 at 14:30
  • Sorry, I was out of the offce for some time. Thanks @Kickstart , that was the reason! – Blaze Sep 11 '15 at 15:24

1 Answers1

0

@Kickstart have answered this question in comment since $Request->post['birth_date'] is an array. I have used answer from here to check for an empty array: Check whether an array is empty

Community
  • 1
  • 1
Blaze
  • 33
  • 6