problems with bindValue

0
    $query = "INSERT INTO
                " . $this->table_name . "
            (data, sexo)
            VALUES
            (:data,:sexo)";

    $stmt->bindValue(':data', $_REQUEST['data']);
    $stmt->bindValue(':sexo', $_REQUEST['sexo']);

is giving an error: Undefined index: sexo . the sexo field is radio button and I did not select it before saving to the database. if I select the sexo field, the data is usually saved in the database, why? wanted to save even if the field is selected or not ...

    
asked by anonymous 11.01.2016 / 18:36

1 answer

0

They are saved because when you select the field of type radio and send the POST when redeeming by the global $ _REQUEST this index will exist. When you do not select it it does not send this index: The reason for the error. if you want to save even without selecting put a value as default to save in the bank. Example:

debug to merge the indexes received by the form print_r ($ _ REQUEST);

avoid missing index error if (! isset ($ _ REQUEST ['sex'])) {    $ sex = 'its value'; }

    
11.01.2016 / 18:44