Database returning 0 when null

Hi all,

I have a form which - when submitted - enters the values into a db and returns the user back to the form which is then prefilled with the data theyve just enetered into the db.

This work fine. HOWEVER, if they dont enter anything into a field that is expecting a decimal number - when they are returned to the page - the field shows ‘0’ whereas it SHOULD show nothing.

The field datatype is decimal(10,1); Null to Yes and Ive set the default value to NULL.

How can I get this working?
Thanks

Can you show us the table’s create statement?

Do you mean the sql which is being called to update the table row?

No, the statement that actually creates the table in the first place.
Though I think the insert/update statement may be useful too and var_dump of the values you insert.

If phpmyadmin is available, try Export table structure.

Either that or use SHOW CREATE TABLE ...

Does the database actually contain a zero in the field, or is it being formatted that way when the form and contents are redisplayed after submissions?

The record is created by another script elsewhere on the site and the values have nothing in (null). When I click the update button and nothing is in the field then ‘0’ appears in the record. So yes, the database actually contains a zero in the field.

Ah - I think I know what you mean.
I havnt included the full sql that is exported, but you can see the field settings here:

current_weight_oz int(11) DEFAULT NULL,

Let me know if you need any further info.
Thanks!

Have a look at the other script which is generating the record, what is it set to return for that field if nothing was entered by the user?

Good idea.
Ive just checked the script thats generating the record and it doesnt mention any other fields other than generating the id for the new record.
… So… is it the fact that - on the Update Form - the fields being passed to the update sql that havnt been entered are auto filling the integer fields with zeros? (The default value for these fields are Null)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.