Jump to content


Photo

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


  • Please log in to reply
3 replies to this topic

#1 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 06 August 2006 - 11:05 AM

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.

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 06 August 2006 - 11:10 AM

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;
follow me on twitter @PHPsycho

#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 06 August 2006 - 11:16 AM

That did the trick, thanks Toon Mariner.

#4 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 06 August 2006 - 11:18 AM

And when you want to change the default of that column you have to do

ALTER `table_name` ALTER `field` SET DEFAULT NULL

RTFM is an almost extinct art form, it should be subsidized.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users