In my PHP code I obtain the value of an input but what I want to do is give it a value in the event that said value does not exist, by default the inputs do not have any value and it correctly collects the data in the variables when I place something but I don't know how to check when there is nothing to give it another value, I did it this way but apparently it is not this way so I would like to know what I have to do.
if(is_null($nombre)) {
$nombre = $lista['nombre'];
}
With PHP 7, you can use the
NULL COALESCENCE OPERATOR
Where:
$nombre
is equal to '$list['username']'??
we assign a default value that is:Sin valor asignado
isset()
EXAMPLE 1
he's going to give me back
EXAMPLE 2
give me back
Operator Reference
I leave you an example of how to add a simple name to the database:
The first thing I use is
isset
that it determines if a variable is defined, more in php.net and then I useempty
that it determines if a variable is empty, more info in php.net .You will not be able to enter anything to the database until you complete the name field and for more security I use PDO- Prepared Statements .
I hope I've helped!