Jump to content

Archived

This topic is now archived and is closed to further replies.

hostfreak

Best way to go about this? -update field in mysql database (php/mysql) *solved*

Recommended Posts

Recently I have just discovered that I had a default of 0 set on a mysql field (if nothing was selected on the form for the field, it would then go to 0), when it should have had a default of nothing if nothing was selected on the form. So what would be the best way for me to go about updating it? I need the ones that contain 0 to be changed to where they are blank. There are a lot of rows, otherwise I would just manually edit them from phpmyadmin. I was thinking this could be done via making a page that selected the field where it had a value of 0. Then making a form that doesn't receive a value and then update it that way? I am not 100% sure how to go about that though. The table name that the field is in, is "users". The field is "id2". Thanks in advance for any replies.

Share this post


Link to post
Share on other sites
just run this query in your phpamyadmin. MAke sure that the fields CAN be null otherwise it will fail.

UPDATE `table_name` SET `field` = NULL WHERE `field` = 0;

Share this post


Link to post
Share on other sites
And when you want to change the default of that column you have to do

[code]ALTER `table_name` ALTER `field` SET DEFAULT NULL[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.