MyBB Community Forums

Full Version: [SOLVED] db->update_query cannot set NULL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have following code in my test2.php file:
$db->update_query('userfields', array("fid".$mybb->settings['drs_setting_user_fid'] => "NULL"), 'ufid = ' . (int)$user['uid'],"",true);

Let's assume "fid".$mybb->settings['drs_setting_user_fid']" is just fid1.

Here, I set fid1 to "NULL" value, but after I have done above code in PHP, and run "SELECT * FROM mybb_userfields WHERE fid1 IS NOT NULL" in myphpadmin, it still search that fid['drs_setting_user_fid']. It shouldn't even be shown. But it shows like following picture:

[attachment=41434]

Blank row between slutty and mcjesus shouldn't even be shown there. I mean, entire row.
All it does is just make fid1 field blank field, but not setting fid1 to NULL to avoid being searched by that select sql command.

How can I make that fid1 actuall NULL that cannot be searched by "SELECT * FROM mybb_userfields WHERE fid1 IS NOT NULL"?
fid are a not null table in the database, you would need to edit the schema.
Thank you very much.
How can I edit scheme to be like that?
Something like the below should do it:

ALTER TABLE mybb_userfields MODIFY fid1 TEXT NULL;
(2019-01-13, 02:06 PM)online0227 Wrote: [ -> ]Thank you very much.
How can I edit scheme to be like that?

There's no need to change it, it's better if you avoid changes like these (edit standard MyBB database schema). Just set/search for a blank value instead of a NULL value:

UPDATE table SET column = ""
SELECT * FROM table WHERE column = ""

$db->update_query('userfields', array("fid".$mybb->settings['drs_setting_user_fid'] => ""), 'ufid = ' . (int)$user['uid'],"", true);
(2019-01-13, 03:01 PM)Mipher Wrote: [ -> ]
(2019-01-13, 02:06 PM)online0227 Wrote: [ -> ]Thank you very much.
How can I edit scheme to be like that?

There's no need to change it, it's better if you avoid changes like these (edit standard MyBB database schema). Just set/search for a blank value instead of a NULL value:

UPDATE table SET column = ""
SELECT * FROM table WHERE column = ""

$db->update_query('userfields', array("fid".$mybb->settings['drs_setting_user_fid'] => ""), 'ufid = ' . (int)$user['uid'],"", true);

Thanks very much.