Hi,
How can set the value to NULL if it was empty because I want to save it as NULL in the database.
I tried:
$user = !empty($user) ? $user : "NULL";
but value is getting set to 0
Kindly help...
Thanks,
Jassim
Hi,
How can set the value to NULL if it was empty because I want to save it as NULL in the database.
I tried:
$user = !empty($user) ? $user : "NULL";
but value is getting set to 0
Kindly help...
Thanks,
Jassim
You didn't post any database code here, so it's impossible to say. For starters, what is the structure of your database? Depending on the data type, NULL values might not be permitted. A field might have a default value of zero.
I'm not sure how PHP nulls transfer to SQL nulls, but setting it to the string "NULL"
will likely end up being treated as a string, which probably gets converted to 0 somewhere if it's being converted to a numeric type. You could try changing your PHP to this and see if it works, setting it to an actual PHP null instead of a string:
$user = !empty($user) ? $user : null;