Mengaw
Mengaw

Reputation: 33

Why I have value of 0 even i didn't put any values?

I have a form

On my column structure on db I set my total_price to decimal(5,2) then i have this input type

<div class="col-md-6" id="property_value">
<?php echo render_input('total_price','total_price',isset($project) ? $project->total_price  : '','number'); ?>
</div>

my model

public function add($data)
{
    $_data['data'] = $data;
    $_data['id']   = $id;
    $_data = do_action('before_update_project', $_data);
    $data = $_data['data'];

    $this->db->where('id', $id);
    $this->db->update('tblprojects', $data);

}

then I click save

The question is, why my data that is sent to the db is 0? Even if I didn't put any value?

Upvotes: 1

Views: 79

Answers (1)

Zoe Edwards
Zoe Edwards

Reputation: 13687

MySQL columns that are numbers of some-sort often default to 0. '' would be an empty string, and (often) numbers are not strings.

If you prefer, you could make the column nullable, and then set the default to NULL.

Upvotes: 6

Related Questions