Set MySQL cell to NULL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xQuasar
Forum Newbie
Posts: 19
Joined: Tue Dec 02, 2008 5:53 pm

Set MySQL cell to NULL

Post by xQuasar »

How do you do it via PHP? I've tried, but the following methods don't work and I'm out of ideas...

Code: Select all

$saltQuery = "UPDATE accounts set salt=NULL where name = '$tusername'";

Code: Select all

$saltQuery = "UPDATE accounts set salt=(NULL) where name = '$tusername'";
Both don't work :( Well, with PHP anyways.

In MySQL Query Browser,

UPDATE `accounts` set `salt`=NULL where `name` = 'name';

WORKS. :(
User avatar
aditya2071990
Forum Contributor
Posts: 106
Joined: Thu May 22, 2008 11:30 am
Location: Hyderabad, India
Contact:

Re: Set MySQL cell to NULL

Post by aditya2071990 »

Did you try:

Code: Select all

$saltQuery = "UPDATE accounts set salt='' where name = '$tusername'";
This will work if in the database, the salt field is not set to "not_null", and if the default value is null...
xQuasar
Forum Newbie
Posts: 19
Joined: Tue Dec 02, 2008 5:53 pm

Re: Set MySQL cell to NULL

Post by xQuasar »

`salt` varchar(32) default NULL

^ That's the column. And I've tried it, it doesn't work with what I'm trying to do.
User avatar
aditya2071990
Forum Contributor
Posts: 106
Joined: Thu May 22, 2008 11:30 am
Location: Hyderabad, India
Contact:

Re: Set MySQL cell to NULL

Post by aditya2071990 »

Are salt and name the only two fields in the table? If they are not, try and omit that from the sql command at all, and fill some other field with some data, then automatically, salt gets a value Null

Code: Select all

$saltQuery = "UPDATE accounts set someOtherField='someOtherValue' where name = '$tusername'";
Post Reply