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

999

I have a form

On my column structure on db I set my total_price todecimal(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?

121

Answer

Solution:

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

If you prefer, you could make the columnnullable, and then set the default toNULL.

People are also looking for solutions to the problem: Uploading File Images with AJAX and PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.