En primer lugar, la columna en su TABLE_NAME
debe aceptar NULL
y es probable que ya reconocen que, con el fin de tener value NULL
, es necesario utilizar
Eg: UPDATE TABLE_NAME SET column_name = NULL
Eg: instead of using column_name = 'NULL'.
So, in a situation where one use a "selected value" to update a table
in database, such as the following very simple example,
Part one,
Condition of the variable:
Checkbox(name = "checkbox")
Eg: if not click, $_POST["checkbox"] = "",
Eg: if clicked, $_POST["checkbox"] = "1".
Now, we must try to make this $_POST["checkbox"] to convert the value ""
to NULL and update to the database table.
An alternative way that I found is to use echo and assign echo value to
a $variable
of course, you already know how to use if {} else {}.
To save echo value to a $variable, I did the following:
Eg: ob_start()
Eg: echo <==hint 1: selected value here.
Eg: $variable1 = ob_get_contents()
Eg: ob_end_clean()
Then, you need to do this again,
Eg: ob_start()
Eg: echo <==hint 2: command line + selected value here.
Eg: $variable2 = ob_get_contents()
Eg: ob_end_clean()
MYSQL will be something like the following:
Eg: UPDATE table_name SET
Eg: name = '$name',
Eg: $variable2,
Eg: date = '$date'
Eg: WHERE id = '$id';
see the trick is to how to make
Eg: $variable2 to show either
Eg: checkbox = NULL
or to show
Eg: checkbox = '1'
Hope this can give you a guide to solve this problem.
I think you have enough knowledge to fill in the blanks. Good luck.
Additional note: you can do the same for (MYSQL) INSERT INTO
¿La columna permite un valor NULL? – poke
Sí, por supuesto. :) – jim
Tabla de ACTUALIZACIÓN columna SET = NULL DONDE ...; ¿No funciona? –